VT100/UNIX -- Using the VT100 emulator with a Remote UNIX(R) System
Running 'termcap' 84/05/16
The following are some tips for using the VT100 emulator when the remote host
is a UNIX(R) system that has the termcap facility.
Most users set the TERM and TERMCAP environment variables by running the
'tset' program in their .login or .profile startup files. When logging in to
a UNIX system through the VT100 emulator, you should specify that your
terminal is a VT132, which is a VT100 with insert/delete character and
insert/delete lines capabilities. The only difference is that a real VT132 is
always 24 lines by 80 columns, and the emulator will use as many lines and
columns as will fit in the DM window. However, you can automatically modify
your TERMCAP variable at login time so that the li and co capabilities reflect
the actual size of the emulator screen. To do so, place the following two
lines, or something similar, in your .login file (this would need to be
changed slightly for use in a .profile file):
tset -s -I vt132 >tset1.$$; setsize <tset1.$$ >tset.$$
source tset.$$; stty nl0; rm tset.$$ tset1.$$
where setsize is the following C-shell script:
#
set size=`sz`
set lines=$size[1]
set columns=$size[2]
sed -e "s/li#[0-9]*:/li#${lines}:/" -e "s/co#[0-9]*:/co#${columns}:/"
and sz is a C program, shown below:
#include <stdio.h>
#include <sgtty.h>
main()
{
FILE *fp;
int fd, lines, columns;
struct sgttyb otty, ntty;
if ((fd = open("/dev/tty", 2)) < 0)
perror("open"), exit(1);
if ((fp = fdopen(fd, "r")) == NULL)
perror("fdopen"), exit(2);
if (gtty(fd, &otty) < 0)
perror("gtty"), exit(3);
ntty = otty;
ntty.sg_flags = (ntty.sg_flags & ~ECHO) | RAW;
stty(fd, &ntty);
write(fd, "\033[50n", 5);
fscanf(fp, "\033[%d;%dS", &lines, &columns);
stty(fd, &otty);
printf("%d %d\n", lines, columns);
}
This program sends ESC[50n to the emulator. This is a non-standard escape
sequence, in response to which the emulator sends back the current screen
size, in the form ESC[nn;mmS, where nn is the number of lines, and mm is the
number of columns.
NOTE: In order for programs such as 'vi' to work properly in windows larger
than 24 lines, there is one change you must make to the termcap entry
for VT100. The sf (scroll forward) capability is given as
sf=30\E7\E[24H\ED\E8. This works by saving the cursor (ESC 7), moving
to the bottom line (ESC[24H, which moves the cursor to the 24th line),
doing an index operation (ESC D), and restoring the cursor (ESC 8). The
problem, of course, is that line 24 may not be the bottom line. This
can be fixed by changing the 24 to some very large number, say 200,
since trying to move the cursor outside the bounds of the screen always
causes it to be placed at the edge of the screen. Thus this change is
safe to make, even when a real VT100 terminal is being used.