Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[3.0.5] patch for resize problem



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@xxxxxxxxxxxxxx)



Messages sorted by: Reverse Date, Date, Thread, Author