[comp.unix.wizards] Window size in 4.3BSD and tset

haynes@ucscc.UCSC.EDU.ucsc.edu (99700000) (09/16/87)

From looking at the code I see that login sets the window size
parameters to zero, and then tset sets them for the terminal
if they are zero to start with and are found in the termcap file.
The result of this is that if you change a terminal from 80-column
mode to 132-column mode and run tset, the window parameters stay
at 80 cols and vi continues to wrap around at the 80th column.
The user has to log out and log back in with the changed terminal
mode to get it to work 'properly'.

Does anybody know why it should be this way, and why tset shouldn't
set the window parameters regardless of whether they were found to
be zero?


haynes@ucscc.ucsc.edu
haynes@ucscc.bitnet
..ucbvax!ucscc!haynes

dave@spool.wisc.edu (Dave Cohrs) (09/16/87)

In article <813@saturn.ucsc.edu> haynes@ucscc.UCSC.EDU (Jim Haynes) writes:
> [ ... ] if you change a terminal from 80-column
>mode to 132-column mode and run tset, the window parameters stay
>at 80 cols and vi continues to wrap around at the 80th column.
>
>Does anybody know why it should be this way, and why tset shouldn't
>set the window parameters regardless of whether they were found to
>be zero?

First, you don't need to log out to let "vi" know your window size
changed.  Check out stty(1).  If you do as you described, follow
that with the command:

	stty columns 132

and run vi (or, if you stopped it, just "fg" it) and it will get your
window size right.

Making "tset" set the window size parameters is a kludge at best.  The
reason you don't want it to do so in general is because lots of people
use these parameters for *real* windows, and windows, in general, can
change size to almost any shape you want.  I doubt that you'd want a
separate termcap entry for each possible window size.  Anyway, once you
set your window to some size, the window manager, or the program
maintaining the individual window, usually sets the window size
parameters automatically and send a SIGWINCH signal, so you don't have
to run "tset" or "stty" for your programs to know the new window size.
If "tset" were to reset these dimensions to your termcap dimensions,
all this would have gone for naught  (comments about whether the BSD
window method is right or not will happily be ignored).

Dave Cohrs                                             Proud member of NOTHING
+1 608 262-6617                             UW-Madison Computer Sciences Dept.
dave@cs.wisc.edu                 ...!{harvard,ihnp4,rutgers,ucbvax}!uwvax!dave

dce@mips.UUCP (David Elliott) (09/16/87)

In article <813@saturn.ucsc.edu> haynes@ucscc.UCSC.EDU (Jim Haynes) writes:
>From looking at the code I see that login sets the window size
>parameters to zero, and then tset sets them for the terminal
>if they are zero to start with and are found in the termcap file.
>The result of this is that if you change a terminal from 80-column
>mode to 132-column mode and run tset, the window parameters stay
>at 80 cols and vi continues to wrap around at the 80th column.
>The user has to log out and log back in with the changed terminal
>mode to get it to work 'properly'.
>
>Does anybody know why it should be this way, and why tset shouldn't
>set the window parameters regardless of whether they were found to
>be zero?

It is pretty bogus behavior.

I changed tset to have a -w option which forces setting of the
window size, but I really think that tset should be leaving the
window size alone.

Before making any statements on this matter, people should consider
terminals like the Ann Arbor Ambassador (various numbers of lines
from 18 to 60), the Wyse 60 (24, 25, 42, or 43 lines by 80 or
132 columns), the Wyse 75 (80 or 132 columns), and the Graphon
GO-235 (your call from 1 to 52 lines).

People like to be able to change between terminal types on the
fly, and tset is a good way to do this, except that, as Jim says,
it screws up your life.

Below is the patch to add the -w option. This may not be the
best solution, but it will work until the world decides on the
correct way.


*** tset.c.old
--- tset.c
***************
*** 479,484 ****
--- 479,485 ----
  int	DoVirtTerm = YES;	/* Set up a virtual terminal */
  int	PadBaud;		/* Min rate of padding needed */
  int	lines, columns;
+ int	Force_size;		/* Force setting of window size */
  
  # define CAPBUFSIZ	1024
  char	Capbuf[CAPBUFSIZ];	/* line from /etc/termcap for this TtyType */
***************
*** 883,888 ****
--- 884,893 ----
  				DoVirtTerm = NO;
  				continue;
  
+ 			  case 'w':	/* set window size */
+ 				Force_size = YES;
+ 				continue;
+ 
  			  default:
  				*p-- = NULL;
  				fatal("Bad flag -", p);
***************
*** 1180,1187 ****
  
  		/* Set window size */
  		(void) ioctl(FILEDES, TIOCGWINSZ, (char *)&win);
! 		if (win.ws_row == 0 && win.ws_col == 0 &&
! 		    lines > 0 && columns > 0) {
  			win.ws_row = lines;
  			win.ws_col = columns;
  			(void) ioctl(FILEDES, TIOCSWINSZ, (char *)&win);
--- 1185,1192 ----
  
  		/* Set window size */
  		(void) ioctl(FILEDES, TIOCGWINSZ, (char *)&win);
! 		if (Force_size || (win.ws_row == 0 && win.ws_col == 0 &&
! 		    lines > 0 && columns > 0)) {
  			win.ws_row = lines;
  			win.ws_col = columns;
  			(void) ioctl(FILEDES, TIOCSWINSZ, (char *)&win);
-- 
David Elliott		{decvax,ucbvax,ihnp4}!decwrl!mips!dce

dce@mips.UUCP (David Elliott) (09/17/87)

In article <4280@spool.wisc.edu> dave@spool.wisc.edu (Dave Cohrs) writes:
>change size to almost any shape you want.  I doubt that you'd want a
>separate termcap entry for each possible window size.  Anyway, once you

This is not a reasonable doubt. I have worked (and currently work) in
environments where some people use sysline and some don't and some people
like lots of lines and some like big characters, and nobody likes
termcap entries that change their screen size. Also, people often use
different types of terminals in different areas (home, office, lab).

So, at Tek, we had a complete set of Ann Arbor Ambassador termcap
entries, and people were allowed to set their default terminal
type (/etc/ttytype and /etc/ttys files).

Also, there exist terminals for which it may not be reasonable to
allow size changes without termcap changes(!). For example, in 80-
column mode, the Wyse 60 terminal allows you to send ^[[y;xH (6
bytes) to do cursor motion. In 132-column mode, it's ^[ayyyRxxxC
(10 bytes), and this can make a difference between whether that
slow processor botches the job or not. Therefore, we actually
have differences in the cm strings.

Another advantage is that if you use tset and different termcap
entries, all you have to do is set up simple aliases to change
to the modes you commonly use, and have tset do the terminal
initialization. Having to go into setup mode is not fun, especially
if the two terminals you use work differently.

The real problem is that whoever added the terminal window size
setting to tset wasn't thinking about terminals that change
size on the fly.

Can you name a terminal for which changing the termcap to one
with a different size would not really change the screen size?
I mean, if I say I'm on an 24x80 terminal and then say I'm
on a 43x132 terminal, why shouldn't the window size change?
-- 
David Elliott		{decvax,ucbvax,ihnp4}!decwrl!mips!dce

rob@philabs.Philips.Com (Rob Robertson) (09/17/87)

In article <4280@spool.wisc.edu> dave@spool.wisc.edu (Dave Cohrs) writes:
>Making "tset" set the window size parameters is a kludge at best.  The
>reason you don't want it to do so in general is because lots of people
>use these parameters for *real* windows, and windows, in general, can
>change size to almost any shape you want.  I doubt that you'd want a
>separate termcap entry for each possible window size.  Anyway, once you
>set your window to some size, the window manager, or the program
>maintaining the individual window, usually sets the window size
>parameters automatically and send a SIGWINCH signal, so you don't have
>to run "tset" or "stty" for your programs to know the new window size.
>If "tset" were to reset these dimensions to your termcap dimensions,
>all this would have gone for naught  (comments about whether the BSD
>window method is right or not will happily be ignored).

This is great if your in an environment with just bitmapped windowing
terminals.  At our site most of the people are hooked up with plain
vt100 compatibles, and don't use windowing.  We had a problem with
people getting lines that rows and columns set wrong in the terminal
driver.  To get everything right, we added a -w switch to tset that
set the rows and columns in the driver to be in agreement with the
termcap.  Those people that don't use windowing and have a tset -wQ in
their .login after the TERM variable is set.

rob



-- 
				william robertson
				rob@philabs.philips.com
		
				"better living through shell scripts"

ado@elsie.UUCP (Arthur David Olson) (09/21/87)

Until the real fix comes along, folks are invited to make the this script
executable and put it in their personal bin directories, named "tset":

	#! /bin/sh

	:
	: This shell script just gets around the bug of tset
	: not redoing rows and cols if they are not zero and you,
	: for example, switch from 80-column mode to 132-column mode.
	:

	stty rows 0 cols 0 1>&2

	exec /usr/ucb/tset ${1+"$@"}

-- 
ado@vax2.nlm.nih.gov	ADO, VAX, and NIH are trademarks of Ampex and DEC.