zsh-users
 help / color / mirror / code / Atom feed
From: Zoltan Hidvegi <hzoli@frontiernet.net>
To: jahwan@math.lsa.umich.edu (Jahwan Kim)
Cc: zsh-users@math.gatech.edu
Subject: Re: zsh always resets LINES to 24.
Date: Wed, 3 Sep 1997 00:40:18 -0400 (EDT)	[thread overview]
Message-ID: <199709030440.AAA01426@hzoli.home> (raw)
In-Reply-To: <19970902225543.21124@supernova.math.lsa.umich.edu> from Jahwan Kim at "Sep 2, 97 10:55:43 pm"

> Hi all,
>     Maybe my post didn't propagated well...

Well, that's the first time I read it.

>     
>     My environment is 31x80 vt-100 (pseudo-)emulator, OSTYPE=solaris2.5.1, and
> TERM=vt100.  Of course, the terminfo entry of vt100 specifies that it
> has 24 lines.  So in my .zshrc, I detect where I login from, and reset LINES
> if I login from home:  export LINES=31.
>     Then at the very first prompt, echo $LINES gives me 24.

Zsh sets LINES and columns to the value obtained from the TIOCGWINSZ
ioctl.  This way, when you resize you xterm, the LINES parameter will
change too.  Normally, when you resize your window, xterm sends SIGWINCH
to the process group of its terminal.  Zsh catches this signal, and
adjusts the window size.  So far so good, you do not resize you terminal,
so zsh does not get SIGWINCH, LINES should not change.  Unfortunately,
it's not that simple.  When zsh runs interactively, the MONITOR option is
enabled to allow you to use fg, bg, ^Z etc.  But this means that when you
start a foreground process, it will run in a separate process group from
zsh, and the terminal's process group is set to the foreground job's
process group.  As a consequence, zsh cannot handle the SIGWINCH signals
xterm sends when you resize the window, so when a foreground process
terminates, zsh goes and asks the terminal for its size.  If the terminal
says that it has 24 lines, zsh just assumes that it was resized, and
sets LINES to 24 even if you had set it to 31 before.

This really means that assigning LINES does not make too much sense.  It
is usefull only on systems which do not have TIOCGWINSZ.

The patch below is an attempt to cure this.  When you manually set
LINES or COLUMNS to something which is different from the last value
returned by TIOCGWINSZ, zsh will not touch it unless it receives a real
SIGWINCH signal.  I hope this helps.  If anyone has a better solution,
please tell me.

Zoltan


*** Src/init.c	1997/07/13 05:24:42	3.1.3.1
--- Src/init.c	1997/09/03 04:28:04
***************
*** 523,533 ****
      createparamtable();     /* create paramater hash table             */
  
  #ifdef TIOCGWINSZ
!     adjustwinsize();
  #else
!     /* Using zero below sets the defaults from termcap */
!     setiparam("COLUMNS", 0);
!     setiparam("LINES", 0);
  #endif
  
  #ifdef HAVE_GETRLIMIT
--- 523,535 ----
      createparamtable();     /* create paramater hash table             */
  
  #ifdef TIOCGWINSZ
!     adjustwinsize(0);
  #else
!     /* columns and lines are normally zero, unless something different *
!      * was inhereted from the environment.  If either of them are zero *
!      * the setiparam calls below set them to the defaults from termcap */
!     setiparam("COLUMNS", columns);
!     setiparam("LINES", lines);
  #endif
  
  #ifdef HAVE_GETRLIMIT
*** Src/jobs.c	1997/06/30 04:48:17	3.1.3.6
--- Src/jobs.c	1997/09/03 03:58:04
***************
*** 167,173 ****
  	if (mypgrp != pgrp && inforeground &&
  	    (jn->gleader == pgrp || (pgrp > 1 && kill(-pgrp, 0) == -1))) {
  	    attachtty(mypgrp);
! 	    adjustwinsize();   /* check window size and adjust if necessary */
  	}
      }
  
--- 167,173 ----
  	if (mypgrp != pgrp && inforeground &&
  	    (jn->gleader == pgrp || (pgrp > 1 && kill(-pgrp, 0) == -1))) {
  	    attachtty(mypgrp);
! 	    adjustwinsize(0);   /* check window size and adjust if necessary */
  	}
      }
  
*** Src/signals.c	1997/06/05 04:44:57	3.1.3.0
--- Src/signals.c	1997/09/03 03:58:10
***************
*** 489,495 ****
  
  #ifdef SIGWINCH
      case SIGWINCH:
!         adjustwinsize();  /* check window size and adjust */
  	if (sigtrapped[SIGWINCH])
  	    dotrap(SIGWINCH);
          break;
--- 489,495 ----
  
  #ifdef SIGWINCH
      case SIGWINCH:
!         adjustwinsize(1);  /* check window size and adjust */
  	if (sigtrapped[SIGWINCH])
  	    dotrap(SIGWINCH);
          break;
*** Src/utils.c	1997/08/02 20:00:18	3.1.3.3
--- Src/utils.c	1997/09/03 04:33:09
***************
*** 790,810 ****
  
  /**/
  void
! adjustwinsize(void)
  {
  #ifdef TIOCGWINSZ
!     int oldcols = columns, oldrows = lines;
  
!     if (SHTTY == -1)
  	return;
  
      ioctl(SHTTY, TIOCGWINSZ, (char *)&shttyinfo.winsize);
      setiparam("COLUMNS", shttyinfo.winsize.ws_col);
      setiparam("LINES", shttyinfo.winsize.ws_row);
!     if (zleactive && (oldcols != columns || oldrows != lines)) {
  	resetneeded = winchanged = 1;
  	refresh();
      }
  #endif   /* TIOCGWINSZ */
  }
  
--- 790,812 ----
  
  /**/
  void
! adjustwinsize(int fromsig)
  {
  #ifdef TIOCGWINSZ
!     static int oldcols, oldrows;
  
!     if (SHTTY == -1 || (!fromsig && (columns != oldcols || lines != oldrows)))
  	return;
  
      ioctl(SHTTY, TIOCGWINSZ, (char *)&shttyinfo.winsize);
      setiparam("COLUMNS", shttyinfo.winsize.ws_col);
      setiparam("LINES", shttyinfo.winsize.ws_row);
!     if (zleactive && (fromsig || oldcols != columns || oldrows != lines)) {
  	resetneeded = winchanged = 1;
  	refresh();
      }
+     oldcols = columns;
+     oldrows = lines;
  #endif   /* TIOCGWINSZ */
  }
  


  reply	other threads:[~1997-09-03  4:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-03  2:55 Jahwan Kim
1997-09-03  4:40 ` Zoltan Hidvegi [this message]
1997-09-03  8:27   ` Andrew Main
1997-09-03 15:44     ` Bart Schaefer
1997-09-03 16:13       ` Andrew Main
1997-09-04  1:15   ` Jahwan Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199709030440.AAA01426@hzoli.home \
    --to=hzoli@frontiernet.net \
    --cc=jahwan@math.lsa.umich.edu \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).