zsh-workers
 help / color / mirror / code / Atom feed
From: Tatsuo Furukawa <frkwtto@osk3.3web.ne.jp>
To: zsh-workers@sunsite.auc.dk
Subject: COLUMNS/LINES environment variable
Date: Tue, 08 Jun 1999 04:13:42 +0900	[thread overview]
Message-ID: <199906071911.EAA12590@pop1.ngy.3web.ne.jp> (raw)


Hello, zsh developers.

I have a complaint for following zsh action.

1. When terminal is resized, COLUMNS/LINES shell variable is changed
   (that's OK), but COLUMNS/LINES environment variable is NOT changed.
   This means that there is a difference between shell variable and
   environment variable. [zsh-3.1.5-pws20, zsh-3.0.6-pre4]

2. COLUMNS/LINES cannot be exported.  "export COLUMNS" command is
   void. [zsh-3.0.6-pre4]

3. COLUMNS/LINES seems to be exported.  But it doesn't.  "export
   COLUMNS" command changes COLUMNS environment variable ONLY once.
   When terminal size is changed again, COLUMNS environment variable
   is not changed. [zsh-3.1.5-pws20]


Ancient zsh does not act so.

This change is executed after zsh-3.0.4 release, and zsh-3.0.5 has
this code.  (And this code also included zsh-3.1.5-pws-XX.)
"ChangeLog" file has following entry.  This change is made internally
by Zoltan, who is zsh maintainer.  This change was not discussed on
the zsh mailing list.  So, Zoltan ONLY knows exact reason.


>> Tue Sep 16 04:43:25 1997  Zolt.. Hidv..i  <hzoli@cs.elte.hu>
>> 
>> 	* Src/zle_tricky.c: Show explanation if there are no or more
>>  	  than one possible completions.
>> 
>> 	* Src/glob.c: Glob after ((#)) with extendedglob set caused 
>>        a coredump
>>
>> 	* Src/builtin.c: read -k sometimes caused a coredump
>> 
>> 	* Src/jobs.c, Src/init.c, Src/params.c, Src/signals.c,
>>  	  Src/utils.c: Setting LINES and COLUMNS manually now works,
>>  	  and it is equivalent to stty rows and stty columns.


According this log, it seems that he just wanted to be same "stty
columns/lines" and "LINES/COLUMNS".  Because ancient zsh has a feature
that LINES/COLUMNS are set when stty rows/columns is executed.

NOTE: This is executed as follows:

    1. stty rows/columns is executed.
    2. SIGWINCH is invoked.
    3. zsh recieves SIGWINCH.
    4. COLUMNS/LINES is changed.

But now zsh does not act such that.  Current zsh receives SIGWINCH,
but it does not change COLUMNS/LINES environment variable.

I think this is just a bug.  Because there is NO reason for deleting
this feature.  And ksh/sh/bash/etc... has this feature, so zsh should
has it too!  I beleve that it is needed for zsh users. (Zoltan, if you
read this mail, please comment it!)

------------------------------------------------------------------------------

Then, I want to propose the feature for terminal size.

1. Following three value is ALWAYS same.

    - Environment variable COLUMNS/LINES.
    - Shell variable COLUMNS/LINES.
    - The value held by TIOCGWINSZ.

2. When starting zsh, terminal size are set by environment variable
   COLUMNS/LINES.

3. When user sets value into COLUMNS/LINES explicitly, zsh also set
   TIOCSWINSZ.

4. When user sets 0 to COLUMNS/LINES, zsh measures terminal size (by
   TIOCGWINSZ), and sets it.

5. When COLUMNS/LINES is "unset", COLUMNS/LINES are deleted.

6. When terminal is resized (by mouse), zsh measures terminal size,
   and sets LINES/COLUMNS.

7. After some command is executed, zsh measures terminal size, and
   sets LINES/COLUMNS.

------------------------------------------------------------------------------

And here is the patch for realizing this proposal. :-)

This patch is for zsh-3.1.5-pws20.  I can make this patch for
zsh-3.0.6-pre4.


diff -urb zsh-3.1.5-pws-20/Src/utils.c zsh-3.1.5-pws-20-modified/Src/utils.c
--- zsh-3.1.5-pws-20/Src/utils.c	Mon May 17 00:32:15 1999
+++ zsh-3.1.5-pws-20-modified/Src/utils.c	Tue Jun  8 03:59:59 1999
@@ -865,30 +865,46 @@
 adjustwinsize(int from)
 {
     int oldcols = columns, oldrows = lines;
+    int term_columns = 0, term_lines = 0;
+    static int adjusting = 0;
+    int size_changed = 0;
 
 #ifdef TIOCGWINSZ
-    static int userlines, usercols;
-
     if (SHTTY == -1)
 	return;
+#endif   /* TIOCGWINSZ */
 
-    if (from == 2)
-	userlines = lines > 0;
-    if (from == 3)
-	usercols = columns > 0;
+    /* To prevent recursion */
+    if (adjusting)
+      return;
 
+    adjusting = 1;
+
+#ifdef TIOCGWINSZ
     if (!ioctl(SHTTY, TIOCGWINSZ, (char *)&shttyinfo.winsize)) {
-	if (!userlines || from == 1)
-	    lines = shttyinfo.winsize.ws_row;
-	if (!usercols || from == 1)
-	    columns = shttyinfo.winsize.ws_col;
+      term_lines   = shttyinfo.winsize.ws_row;
+      term_columns = shttyinfo.winsize.ws_col;
     }
+
+    if ((from == 0) || (from == 1)) {
+      lines   = term_lines;
+      columns = term_columns;
+    }
+
+    if ((from == 2) && (lines <= 0))
+      lines = term_lines;
+    if ((from == 3) && (columns <= 0))
+      columns = term_columns;
 #endif   /* TIOCGWINSZ */
 
+
+    /* When lines/columns are invalid value... */
     if (lines <= 0)
 	lines = tclines > 0 ? tclines : 24;
     if (columns <= 0)
 	columns = tccolumns > 0 ? tccolumns : 80;
+
+    /* setting termflags */
     if (lines > 2)
 	termflags &= ~TERM_SHORT;
     else
@@ -898,18 +914,37 @@
     else
 	termflags |= TERM_NARROW;
 
+
 #ifdef TIOCGWINSZ
-    if (interact && from >= 2) {
+    if (interact && (lines != term_lines || columns != term_columns)) {
 	shttyinfo.winsize.ws_row = lines;
 	shttyinfo.winsize.ws_col = columns;
 	ioctl(SHTTY, TIOCSWINSZ, (char *)&shttyinfo.winsize);
+      size_changed = 1;
     }
 #endif
 
-    if (zleactive && (from >= 2 || oldcols != columns || oldrows != lines)) {
+    if (interact) {
+      if (oldcols != columns) {
+        if (getsparam("COLUMNS")) { /* check whether "COLUMNS" is exist or not */
+          setiparam("COLUMNS", columns);
+          size_changed = 1;
+        }
+      }
+      if (oldrows != lines) {
+        if (getsparam("LINES")) { /* check whether "LINES" is exist or not */
+          setiparam("LINES", lines);
+          size_changed = 1;
+        }
+      }
+    }
+
+    if (zleactive && size_changed) {
 	resetneeded = winchanged = 1;
 	zrefresh();
     }
+
+    adjusting = 0;
 }
 
 /* Move a fd to a place >= 10 and mark the new fd in fdtable.  If the fd *

-- 
Tatsuo Furukawa (frkwtto@osk3.3web.ne.jp)


             reply	other threads:[~1999-06-07 19:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-07 19:13 Tatsuo Furukawa [this message]
1999-06-07 21:59 ` Bart Schaefer
1999-06-09 17:13   ` Tatsuo Furukawa
1999-06-09 18:08     ` Bart Schaefer

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=199906071911.EAA12590@pop1.ngy.3web.ne.jp \
    --to=frkwtto@osk3.3web.ne.jp \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).