Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When using the serial console of my system I always end up with $COLUMNS=80 and $LINES=24.

While I can change these variables manually it is somewhat annoying to do this any time when the client side terminal window has been resized.

Usually I'm connecting to the console using screen /dev/mytty baudrate.

Changing the $TERM environment variable to "screen" or "xterm" does not help.

Will I need to call getty with some of those instead of vt100?

Needless to say that all of this works fine, when I connect to the same machine using ssh.

share|improve this question

Just for the record, here is the answer to this Problem (Usenet won):

Console Applications running inside virtual terminal applications (xterm, rxvt and friends) will receive SIGWINCH after a resize operation has taken place. Thus the application will be able to redraw the window etc. in the corresponding signal handler.

Unfortunately when using a serial console, there is no such mechanism.

It is however possible for the application to actively ask for the current console Window size. So the second best thing is to do this every time a command prompt is printed by the shell.

In bash this can be achieved using the following in bashrc:

if [ $(tty) == '/dev/ttyS0' ]; then
  trap resize DEBUG
fi

The actual sourcecode of the resize command can be found here.

Of course this will not change the console size settings in a console application during runtime.

share|improve this answer
    
Shouldn’t it be possible to run a protocol over the serial line, that does offer all the features? I mean we do have a client and a server. They could use inband escape sequences to do just about everything, and still work with a plain text serial console! – Evi1M4chine Feb 2 at 14:35
    
Actually, the comment in the code makes it plain that it's not the version of resize which is installed on your system. – Thomas Dickey Feb 16 at 15:23

"Resizable" terminals as such are a result of NAWS (Negotiate About Window Size from RFC 1073 Telnet Window Size Option).

If you are connected directly to the computer using a serial port, there is no negotiation involved, and the computer has no direct knowledge of your terminal's screen-size.

If a terminal can negotiate the size, the computer will send SIGWINCH to applications running in the terminal, telling them to update their notion of the screensize.

When the computer does not know the screensize, it typically sets the size shown by stty -a (rows and columns) to zero. For interactive use, this is a little unfriendly, and some systems use environment variables LINES and COLUMNS to help. The values assigned may be derived from the terminal description; more often they are simply hardcoded. The convention for these variables requires that they take effect unless explicitly suppressed, e.g., in curses applications use_env function. On the positive side, those variables can be useful when no reliable information is available. On the negative side, there is no convenient method for altering those variables.

The resize program (a utility provided with xterm) can use the VT100-style cursor position report escape sequence for determining the screen size. This can be run from the command-line; there is (again) no convenient way to do it automatically. As a side-effect, resize updates the information on rows/columns seen by stty. Its use for providing updated environment variables is mainly useful for cases such as this, where LINES and COLUMNS are set, and should be updated.

share|improve this answer

Here is another solution that worked great for me on my embedded Linux system (Overo running Angstrom). I just ran it from my .bashrc file. I didn't want to use resize because that requires installing some X packages, and I didn't want that.

http://shallowsky.com/blog/tags/embedded/

share|improve this answer
2  
Please don't just post a link: include the relevant detail so that the information is available here as well... – jasonwryan May 3 '14 at 0:51
    
Too bad it needs Python. – Craig McQueen Oct 31 '14 at 4:52

Like the commentators before me mentioned there is no alternative to calling resize after every command, if you don't have this command and you don't want to install a package where it's in, here are two POSIX script that do the same using the ANSI terminal escape codes:

res() {

  old=$(stty -g)
  stty raw -echo min 0 time 5

  printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
  IFS='[;R' read -r _ rows cols _ < /dev/tty

  stty "$old"

  # echo "cols:$cols"
  # echo "rows:$rows"
  stty cols "$cols" rows "$rows"
}

This one is influenced by resize.sh from xterm (https://fossies.org/linux/xterm/vttests/resize.sh). Cursor position is saved, moved as far left-bottom as possible, reported, and moved back.

res2() {

  old=$(stty -g)
  stty raw -echo min 0 time 5

  printf '\033[18t' > /dev/tty
  IFS=';t' read -r _ rows cols _ < /dev/tty

  stty "$old"

  # echo "cols:$cols"
  # echo "rows:$rows"
  stty cols "$cols" rows "$rows"
}

This one is influenced by https://wiki.archlinux.org/index.php/working_with_the_serial_console#Resizing_a_terminal. A special xterm code specifically for getting this information is used here (implemented in a lot of various terminal emulators though). See also http://invisible-island.net/xterm/ctlseqs/ctlseqs.html ("Report the size of the text area in characters.").

share|improve this answer

Why not try minicom, kermit or gtkterm, I don't think they have that problem?

share|improve this answer
    
Nope, this does not seem to be a Problem of the Client side. It does not matter if minicom or screen is used. – Sven Geggus Jul 13 '11 at 14:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.