zsh-workers
 help / color / mirror / code / Atom feed
* [3.0.5] patch for resize problem
@ 1998-10-24 10:52 Tatsuo Furukawa
  1998-10-24 18:43 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Tatsuo Furukawa @ 1998-10-24 10:52 UTC (permalink / raw)
  To: zsh-workers; +Cc: olsenc


Hello zsh developpers.

I fixed the zsh 3.0.5 resize problem.  Which is already reported by
Clint Olsen. (archive ID is 3968, 3985-3989)


 What is "resize problem"?
===========================

Zsh 3.0.5 believes LINES and COLUMNS fanatically.  If I changed
terminal size, SIGWINCH is sent to zsh, but zsh does not measure
terminal size.  This symptoms is observed only 3.0.5.

To confirm this, execute following script:

-------------- CUT here ------------------
#/do/not/write/like/a/bin/zsh
#

while 
do
    ENV_COL=`env | grep COLUMNS`

    echo $ZSH_VERSION "\t" $COLUMNS "\t" $ENV_COL
    sleep 1
done
-------------- CUT here ------------------

and execure as follows:

    $ /bin/zsh this-script

This script prints terminal width forever.  Then, change the terminal
width.  What will be observed?
    
    zsh-3.0.2       New terminal width is printed.
    zsh-3.0.5       Old terminal width is still printed.
    zsh-3.1.2       New terminal width is printed.
    zsh-3.1.4       New terminal width is printed.


3.0.5 is different.  I (and maybe Clint) hope that 3.0.5 acts same.


 The Patch
===========

I incorporated 3.1.4's resize code into 3.0.5.  And it works well.  I
made a patch.  This patch is for 3.0.5.  I recommend that this patch
will be adopted 3.0.6.



diff -ur zsh-3.0.5/Src/init.c zsh-3.0.5-column/Src/init.c
--- zsh-3.0.5/Src/init.c	Fri Sep 26 10:42:16 1997
+++ zsh-3.0.5-column/Src/init.c	Fri Oct 23 18:45:14 1998
@@ -602,13 +602,13 @@
     createparamtable();     /* create paramater hash table             */
 
 #ifdef TIOCGWINSZ
-    adjustwinsize(0);
+    adjustwinsize();
 #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);
+    setiparam("COLUMNS", 0);
+    setiparam("LINES", 0);
 #endif
 
     /* create hash table for multi-character emacs bindings */
diff -ur zsh-3.0.5/Src/jobs.c zsh-3.0.5-column/Src/jobs.c
--- zsh-3.0.5/Src/jobs.c	Fri Sep 26 10:42:17 1997
+++ zsh-3.0.5-column/Src/jobs.c	Fri Oct 23 18:45:40 1998
@@ -166,7 +166,7 @@
 	if (mypgrp != pgrp && inforeground &&
 	    (jn->gleader == pgrp || (pgrp > 1 && kill(-pgrp, 0) == -1))) {
 	    attachtty(mypgrp);
-	    adjustwinsize(0);   /* check window size and adjust if necessary */
+	    adjustwinsize();   /* check window size and adjust if necessary */
 	}
     }
 
diff -ur zsh-3.0.5/Src/params.c zsh-3.0.5-column/Src/params.c
--- zsh-3.0.5/Src/params.c	Fri Sep 26 10:42:17 1997
+++ zsh-3.0.5-column/Src/params.c	Fri Oct 23 18:52:30 1998
@@ -1242,9 +1242,23 @@
 {
     long *p = (long *)pm->data;
 
+    if (p == & columns) {
+	if(x <= 0)
+	    x = tccolumns > 0 ? tccolumns : 80;
+	if (x > 2)
+	    termflags &= ~TERM_NARROW;
+	else
+	    termflags |= TERM_NARROW;
+    } else if (p == & lines) {
+	if(x <= 0)
+	    x = tclines > 0 ? tclines : 24;
+	if (x > 2)
+	    termflags &= ~TERM_SHORT;
+	else
+	    termflags |= TERM_SHORT;
+    }
+
     *p = x;
-    if (p == &lines || p == &columns)
-	adjustwinsize(2 + (p == &columns));
 }
 
 /* Function to set value of generic special scalar    *
diff -ur zsh-3.0.5/Src/signals.c zsh-3.0.5-column/Src/signals.c
--- zsh-3.0.5/Src/signals.c	Fri Sep 26 10:42:18 1997
+++ zsh-3.0.5-column/Src/signals.c	Fri Oct 23 18:46:01 1998
@@ -485,7 +485,7 @@
 
 #ifdef SIGWINCH
     case SIGWINCH:
-        adjustwinsize(1);  /* check window size and adjust */
+        adjustwinsize();  /* check window size and adjust */
 	if (sigtrapped[SIGWINCH])
 	    dotrap(SIGWINCH);
         break;
diff -ur zsh-3.0.5/Src/utils.c zsh-3.0.5-column/Src/utils.c
--- zsh-3.0.5/Src/utils.c	Fri Sep 26 10:42:18 1997
+++ zsh-3.0.5-column/Src/utils.c	Fri Oct 23 18:43:37 1998
@@ -828,63 +828,26 @@
 extern winchanged;
 #endif
 
-/* check the size of the window and adjust if necessary. *
- * The value of from:					 *
- *   0: called from update_job or setupvals		 *
- *   1: called from the SIGWINCH handler		 *
- *   2: the user have just changed LINES manually	 *
- *   3: the user have just changed COLUMNS manually      */
+/* check the size of the window and adjust if necessary */
 
 /**/
 void
-adjustwinsize(int from)
+adjustwinsize(void)
 {
-    int oldcols = columns, oldrows = lines;
-
 #ifdef TIOCGWINSZ
-    static int userlines, usercols;
+    int oldcols = columns, oldrows = lines;
 
     if (SHTTY == -1)
 	return;
 
-    if (from == 2)
-	userlines = lines > 0;
-    if (from == 3)
-	usercols = columns > 0;
-
-    if (!ioctl(SHTTY, TIOCGWINSZ, (char *)&shttyinfo.winsize)) {
-	if (!userlines)
-	    lines = shttyinfo.winsize.ws_row;
-	if (!usercols)
-	    columns = shttyinfo.winsize.ws_col;
-    }
-#endif   /* TIOCGWINSZ */
-
-    if (lines <= 0)
-	lines = tclines > 0 ? tclines : 24;
-    if (columns <= 0)
-	columns = tccolumns > 0 ? tccolumns : 80;
-    if (lines > 2)
-	termflags &= ~TERM_SHORT;
-    else
-	termflags |= TERM_SHORT;
-    if (columns > 2)
-	termflags &= ~TERM_NARROW;
-    else
-	termflags |= TERM_NARROW;
-
-#ifdef TIOCGWINSZ
-    if (from >= 2) {
-	shttyinfo.winsize.ws_row = lines;
-	shttyinfo.winsize.ws_col = columns;
-	ioctl(SHTTY, TIOCSWINSZ, (char *)&shttyinfo.winsize);
-    }
-#endif
-
-    if (zleactive && (from >= 2 || oldcols != columns || oldrows != lines)) {
+    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 */
 }
 
 /* Move a fd to a place >= 10 and mark the new fd in fdtable.  If the fd *

--
Tatsuo Furukawa  (frkwtto@wnn.club.or.jp)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [3.0.5] patch for resize problem
  1998-10-24 10:52 [3.0.5] patch for resize problem Tatsuo Furukawa
@ 1998-10-24 18:43 ` Bart Schaefer
  1998-10-27 16:22   ` Tatsuo Furukawa
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 1998-10-24 18:43 UTC (permalink / raw)
  To: Tatsuo Furukawa, zsh-workers; +Cc: olsenc

On Oct 24,  7:52pm, Tatsuo Furukawa wrote:
} Subject: [3.0.5] patch for resize problem
}
} Hello zsh developpers.
} 
} I incorporated 3.1.4's resize code into 3.0.5.  And it works well.

Unfortunately, what you did, except for irrelevant details in params.c,
is revert back to the 3.0.4 code.  The semantics in 3.1.4 are unchanged
from 3.0.4, so incorporating 3.1.4 is in this instance a step backwards.

Although I don't entirely like the 3.0.5 behavior, *I've* never had a
problem with eval $(resize) setting LINES and COLUMNS correctly (which
was Clint's original complaint).  It is true that 3.0.5 doesn't respond
to SIGWINCH, but the 3.0.4 behavior has different bugs that the changes
in 3.0.5 were intended to address, and I presume it is an accident that
the 3.0.5 code isn't in 3.1.4.

If Clint is still out there listening:  Does zsh receive a SIGWINCH when
you eval $(resize)?  If so, guess what:  You're probably not getting any
output from $(resize) at all, because of the EINTR bug in readoutput()
for which I posted a patch a few days ago.  Please try applying my patch
from zsh-users/1880 (note that's zsh-USERS, not -workers) and tell us if
resize starts working for you again.

If the EINTR patch works, then

    TRAPWINCH() { eval $(resize) }

should work too.  (It does for me even without the EINTR patch, but then
I never had any problems with resize to begin with.)

If all you care about is having zsh believe SIGWINCH signals, then a much
simpler patch to 3.0.5, which doesn't back out the other bug fixes, is:

Index: Src/utils.c
--- utils.c	Sat May 23 08:53:31 1998
+++ -	Sat Oct 24 11:36:47 1998
@@ -855,9 +855,9 @@
 	usercols = columns > 0;
 
     if (!ioctl(SHTTY, TIOCGWINSZ, (char *)&shttyinfo.winsize)) {
-	if (!userlines)
+	if (!userlines || from == 1)
 	    lines = shttyinfo.winsize.ws_row;
-	if (!usercols)
+	if (!usercols || from == 1)
 	    columns = shttyinfo.winsize.ws_col;
     }
 #endif   /* TIOCGWINSZ */


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [3.0.5] patch for resize problem
  1998-10-24 18:43 ` Bart Schaefer
@ 1998-10-27 16:22   ` Tatsuo Furukawa
  0 siblings, 0 replies; 3+ messages in thread
From: Tatsuo Furukawa @ 1998-10-27 16:22 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers, olsenc


Hi,

Bart> Unfortunately, what you did, except for irrelevant details in
Bart> params.c, is revert back to the 3.0.4 code.

Oh! Ouch!!

Bart> Although I don't entirely like the 3.0.5 behavior, *I've* never
Bart> had a problem with eval $(resize) setting LINES and COLUMNS
Bart> correctly (which was Clint's original complaint).

Yes, me too.  My (original, unpatched) zsh 3.0.5 does not have a
problem about "eval $(resize)".  Zsh always set correct LINES and
COLUMNS when I invoke eval $(resize).

But I hope I don't have to invoke "eval $(resize)".  I hope zsh always
set LINES and COLUMNS to right value automatically.

Because I use RPROMPT.  As you know, to use RPROMPT, I must always set
COLUMNS to right value.  To do this, I must invoke "eval $(resize)"
every time when I change the terminal size.  It makes me irritated.


Bart> If all you care about is having zsh believe SIGWINCH signals,
Bart> then a much simpler patch to 3.0.5, which doesn't back out the
Bart> other bug fixes, is:
    (snip)

Cool!  It works well!  Thank you Bart.  With this patch, I can say
Goodbye to "eval $(resize)".

--
Tatsuo Furukawa  (frkwtto@wnn.club.or.jp)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-10-27 16:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-24 10:52 [3.0.5] patch for resize problem Tatsuo Furukawa
1998-10-24 18:43 ` Bart Schaefer
1998-10-27 16:22   ` Tatsuo Furukawa

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).