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

Re: COLUMNS/LINES environment variable



Sorry for late reply, and thank for response.

Bart> I think it was discussed, 

Oh, sorry.  Before I wrote the mail, I searched zsh mail archive, but
my range was narrow....

Bart> Here are some messages about it

Thank you!  I can catched up reading these messages.

Bart>  (sorry for not having zsh-workers article numbers

Please don't mind.  Your information is perfect.  I could get the
messages from zsh-workers archive.  And, I added article numbers. :-)

Date	   No					Subject
03/30/97   3053   zefram    setting window size
03/31/97   3063   zefram    window size bugfix
05/10/97   3114   schaefer  Re: test patches
05/10/97   3119   hzoli     Re: test patches
05/18/97   3156   hzoli     More LINES/COLUMNS changes
12/09/97   3648   schaefer  zsh 3.0.5 WINSZ stuff is messing up my vi
12/09/97   3649   schaefer  PATCH: 3.0.5: terminal size	should
                            not be reset by zsh -c


Bart> 3.0.5 doesn't even change the internal lines/columns on WINCH.
Bart> (We had this conversation last October.)

Yes, I remember. (And I forgot to add this.)  Current zsh code is
applied following patch.  This comes from zsh-workers/4447.

>> 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 */

This patch makes zsh stranger than original 3.0.5.  Because,
environment variable COLUMNS/LINES are different from shell variable.
Users can check COLUMNS/LINES using "echo $COLUMNS", but their
application may not receive that value.  (Environment variable
$COLUMNS are passed to their application.)


Bart> (We had this conversation last October.)

Yes.  Your advice (TRAPWINCH() { eval $(resize) }) WAS very valuable
for me.  But it is not work at following case:

    1. Rlogin remote host
    2. Change terminal size
    3. (Then, COLUMNS/LINES are set to correct value)
    4. Exit from remote host
    5. COLUMNS/LINES are old value!

This phenomenon is NOT appeared by another shell.  My dissatisfaction
is "Why ONLY zsh can not?".  And my hope is "Other shell can do it.
So, zsh can do it too!".


Bart> There's an additional source of lines/columns information: The
Bart> terminal information database (either termcap or terminfo).

Oh, I forgot.  But termcap/terminfo value is not important for
resizable terminal.  This value should be used for the last resort for
measureing terminal size, I think.  (And zsh already does.)


Bart> The problem with asserting "value is ALWAYS same" is that, at
Bart> shell startup, you may have three conflicting values for
Bart> terminal size.  Any one of them may be wrong in various
Bart> circumstances, and it's difficult/impossible to cause the
Bart> term{cap,info} one to change.  Which one do we believe?

This problem is exist in ALL terminal related programs.  So, I
investigated some programs.

[ vi ($Revision: 78.2.1.8 $  HP-UX 10.20) ]

When startup,

    1. If COLUMNS/LINES are exist, this value is used.  If terminal is
       resized, TIOCGWINSZ value is used (COLUMNS/LINES are ignored).

    2. If COLUMNS/LINES are not exist, TIOCGWINSZ value is used.  If
       terminal is resized, TIOCGWINSZ value is used.

[ less (Version 3.3.2  HP-UX 10.20) ]

When startup,

    1. If COLUMNS/LINES are exist, this value is used.  If terminal is
       resized, COLUMNS/LINES is STILL used (terminal is resized, but
       less is NOT resized).

    2. If COLUMNS/LINES are not exist, TIOCGWINSZ value is used.  If
       terminal is resized, TIOCGWINSZ value is used.

[POSIX shell  (HP-UX 10.20)]

When startup,

    (same as vi)


>From this result, my recommendation is as follows:

[Zsh (I hope...)]

When startup,

    1. If COLUMNS/LINES are exist, use this value.
    2. If above is void, use TIOCGWINSZ value.
    3. If above is void, use termcap/terminfo value.
    4. If above is void, use 80*25.

When resized,

    1. TIOCGWINSZ value is used.  (Even if COLUMNS/LINES are exist.)

I> 7. After some command is executed, zsh measures terminal size, and
I>    sets LINES/COLUMNS.
Bart> "After some command" you are back in the same boat as you are at
Bart> shell startup -- you have no idea if the terminal was resized
Bart> during the external command or if the tty driver values for
Bart> lines/columns have simply been wrong all along.

How about this?

"After some command",

    1. If COLUMNS/LINES are different from internal columns/lines
       value, COLUMNS/LINES are used.
    2. If above is void, use TIOCGWINSZ value.

Note that When COLUMNS/LINES are used, zsh issues TIOCSWINSZ.  So,
once zsh is started, COLUMNS/LINES and TIOCGWINSZ are same.

Bart> Probably in that last case we could see whether the tty driver
Bart> values of lines/columns actually changed since the last
Bart> TIOCGWINSZ, and elect to believe them in that event.

Your idea is also good for me. :-)


Bart> So we chose to do nothing (again unless COLUMNS/LINES give no
Bart> information).

If this policy is still not changed, could you add some options?  Like
this:

>>   setopt autotermresize        zsh measures terminal size and 
>>                                sets COLUMNS/LINES.
>>   unsetopt autotermresize      zsh does not measure terminal size,
>>                                user must set COLUMNS/LINES manually.
>>
>>  If you want to act like POSIX shell, set autotermresize.


Bart> The correct course for the user is to explicitly set
Bart> LINES/COLUMNS if he knows the correct values [e.g. eval
Bart> $(resize)] or to unset them if he knows that the terminal driver
Bart> has the right values.

This has following inconvenience:

    1. The script/program which uses COLUMNS/LINES and don't use
       TIOCSWINSZ is not work well.

    2. When user execute "eval $(resize)" accidentally, zsh will not
       change terminal size.

    3. My linux/HP-UX system gives LINES/COLUMNS when I logged in.
       So, I must unset LINES/COLUMNS explicitly.

If you think the user 

If user have to tell "terminal driver has the right values" to zsh,
will you change the way? ("unset LINES/COLUMNS method" has the
problem.  How about setopt? (like autotermresize))



Bart> We should document this somewhere, at least in the FAQ, and fix
Bart> any export issues.

That's nice!  If export issues is fixed, my dissatisfaction will be
reduced undoubtedly.

-- 
Tatsuo Furukawa (frkwtto@xxxxxxxxxxxxxxx)



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