telnet and $LINES

Kevin Buettner kev@primenet.com
Thu, 28 Sep 2000 15:54:00 -0700


On Sep 28,  2:53pm, der.hans wrote:

> using Net::Telnet to automate some stuff and am apparently running into a
> prob due to screen length or some such.
> 
> If I open an xterm and do the stuff by hand it auto prompts for "more" at
> the end of the screen. This also happens if I increase or decrease the
> size of my xterm, e.g. it works correctly.
> 
> When resizing the xterm $LINES changes as appropriate and it works, but
> changing $LINES doesn't affect the number of lines scrolled before being
> prompted for more.
> 
> Anybody know how else this would be done? With Net::Telnet I get 2 lines
> per scroll, which is highly inefficient for the number of lines I'm
> parsing.

Try using Term::Size.  (I just glanced at the code in
Term-Size-0.2.tar.gz and it does the right thing.  That is, it queries
the OS and gets the info back in struct winsize.)

BTW, the shell (some shells anyway) set $LINES based upon the size of
the xterm (or other terminal window) that it's running in.  When you
resize the window, the shell gets the SIGWINCH signal, it queries the
size using the TIOCGWINSZ ioctl.  The results are returned in struct
winsize and the shell uses these results to update $LINES and
$COLUMNS.  An application written in C (like ``more'' or an editor)
can use the same mechanism to adjust itself for the resized window. 
You may want your Perl application to watch for the SIGWINCH signal
and perform similar adjustments as well.

A good reference for this type of thing is "Advanced Programming in
the Unix Environment" by W. Richard Stevens.  (I *highly* recommend
this book.)

Kevin