|Terminal window size detection over serial connections|
I occasionally need to login to embedded Linux devices over serial connections. One frustrating thing about using a serial login is that programs running on the remote device don't know the window size of my local terminal emulator, so 80x24 is usually assumed even if I've resized my xterm to be much bigger (or even full screen!). Most network remote login protocols, such as ssh and telnet, use protocol features to communicate window change events transparently. Unfortunately, there is no such facility for serial logins, because there is no protocol.
To help ease the pain of this problem, I wrote a small C program called fixterm which runs on the remote machine and uses a little-known feature of some terminal emulators to query the actual window size and update the kernel's notion of the tty's window size. Unfortunately, this program doesn't automatically update the tty whenever you resize the window -- you still have to run the program each time. However, it does save a few steps compared to manually figuring out the window size in characters and typing "stty rows 24 columns 80". This program seems to work fine with xterm, Gnome Terminal, and PuTTY, but not with Konsole which does not support the window size query feature.
It is important to note that fixterm does not work with GNU Screen out of the box, even if you are running screen in a supported terminal emulator such as xterm, because screen provides its own terminal emulation layer that shields the client programs from the outer terminal. As a frequent screen user, I found this annoying enough that I created a small patch to add the required window size support. If you happen to be a screen user, you may want to use this patch by performing the following steps:
- Download screen 4.0.2 from the GNU ftp site.
- Download my patch.
- tar xvfpz screen-4.0.2.tar.gz
- cd screen-4.0.2
- patch -p1 < ../screen-4.0.2-sizereport.patch
- make install
Here are the goods: