2015년 5월 19일 화요일

Issues with Terminator and GNU Screen

One of the first Linux distros I used was Crunchbang Linux based on Ubuntu 9.04. The default terminal was terminator, and I thought it was so cool how you could split terminal windows vertically and horizontally multiple times using the hotkeys C-S-o (horizontal split), C-S-e (vertical split). I have continued using terminator on all my personal machines and even in some VM's where terminator's ability to split a window into multiple sub-windows is very helpful for making the most of limited screen real estate.

When I was a Linux hobbyist, I almost never used ssh or telnet, let alone a serial console cable to connect to other machines, but now as a Linux engineer I often connect remotely to dozens of different machines in one session. Using gnome-terminal with tabs or terminator with split windows has its limits when working with more than a handful of remote machines. I started using GNU Screen as my terminal multiplexer of choice because unlike tmux (which many people prefer to Screen) GNU Screen supports serial console connections with much less fuss than minicom and with much more robustness than putty.

Over the last several months I have launched GNU Screen from within terminator, which does a passable job of supporting screen for simple terminal tasks. The problem, however, is that if you try to use vi/vim in a screen session that is itself launched inside terminator, upon exiting from your vim editing session, GNU Screen's output will only scroll in the top half of the terminator window!

Another weird occurrence when using GNU Screen from within terminator is that after several thousand lines are stored in terminator's scrollback buffer (which I have set to 'unlimited') during a serial console session, Screen will start returning gibberish even though the console speed is set to the correct setting for your hardware.

Check out this totally broken login screen (which is supposed to be a standard /etc/issue banner)

#####################################################################
 #  T␤␋⎽ ⎽≤⎽├␊└ ␋⎽ °⎺⎼ ├␤␊ ┤⎽␊ ⎺° ▒┤├␤⎺⎼␋≥␊␍ ┤⎽␊⎼⎽ ⎺┼┌≤.             #
 #  I┼␍␋┴␋␍┤▒┌⎽ ┤⎽␋┼± ├␤␋⎽ ␌⎺└⎻┤├␊⎼ ⎽≤⎽├␊└ ┬␋├␤⎺┤├ ▒┤├␤⎺⎼␋├≤, ⎺⎼ ␋┼  #
 #  ␊│␌␊⎽⎽ ⎺° ├␤␊␋⎼ ▒┤├␤⎺⎼␋├≤, ▒⎼␊ ⎽┤␉┘␊␌├ ├⎺ ␤▒┴␋┼± ▒┌┌ ⎺° ├␤␊␋⎼    #
 #  ▒␌├␋┴␋├␋␊⎽ ⎺┼ ├␤␋⎽ ⎽≤⎽├␊└ └⎺┼␋├⎺⎼␊␍ ▒┼␍ ⎼␊␌⎺⎼␍␊␍ ␉≤ ⎽≤⎽├␊└       #
 #  ⎻␊⎼⎽⎺┼┼␊┌.                                                       #
 #                                                                   #
 #  I┼ ├␤␊ ␌⎺┤⎼⎽␊ ⎺° └⎺┼␋├⎺⎼␋┼± ␋┼␍␋┴␋␍┤▒┌⎽ ␋└⎻⎼⎺⎻␊⎼┌≤ ┤⎽␋┼± ├␤␋⎽    #

The blocks are control characters. The banner should look something like:

#####################################################################
 #  This system is for the use of authorized users only.             #
 #  Individuals using this computer system without authority, or in  #
 #  excess of their authority, are subject to having all of their    #
 #  activities on this system monitored and recorded by system       #
 #  personnel.
...
This problem can be solved by detaching the screen session with C-a d, exiting the current terminator session, opening an entirely new terminator session and attaching to the detached GNU Screen session with screen -r.

What is interesting is that I have not run into the scrolling bug (in which text only scrolls in the top half of the terminal window.) when using vi/vim within a screen session launched from lxterminal. (Note: scrolling issues after invoking vim in a GNU screen session can be mostly fixed by adding altscreen on to your ~/.screenrc)

Although I still enjoy using terminator for day-to-day CLI tasks on my local machine, for remote sessions I now use GNU Screen with other terminal emulators besides terminator. I have tested GNU Screen and xfce4-terminal and lxterminal and I suspect that screen will also work well with gnome-terminal without the bugs I experienced with terminator.


Postscript 2015-10-11

After several months of using various terminals with GNU Screen over serial console, I have learned that serial console text corruption issue that often occurs after a remote machine reboot when the scrollback buffer is quite full affects all the vte-dependent terminals I've used including terminator, lxterminal, and xfce4-terminal.