COLUMNS and LINES environment variables
Philipp Marek
philipp.marek at linbit.com
Tue Sep 1 16:52:58 AEST 2015
> > Instead of just playing nethack, I've been building a client that
> > would log in to nethack at alt.org and using a pipe to get the login data
> > from pwsafe directly onto the server.
> > All of this works brilliantly after playing with some stty magic (full
> > script in [0]), however, this way the terminal size is burned into
> > 80x24, which is way smaller than my graphical terminal.
> >
> > Anyway, I proceeded grepping some of the openssh source code and wrote
> > this patch [1], which I have locally tested with great success.
>
> The problem with doing it via enviornment variables is that they
> will become invalid if the client ever changes the size of their
> window. TTYs support sending SIGWINCH for this and OpenSSH handles
> this already.
>
> Your program should be able to get the correct window size at any
> time using:
>
> struct winsize ws;
> if (ioctl(ttyfd, TIOCGWINSZ, &ws) != 0)
> error(...);
The "script" version of that is calling "tput cols" and "tput lines",
parsing the text output as integers...
More information about the openssh-unix-dev
mailing list