Sec, blogmal! - tidbits - titeinhibit



April '18



Wed, 15 Sep 2010

Fixing the alternate screen problem

Many of you probably know the annoying behaviour of console-based programs like less or vi restoring the screen after exiting so that the text you just had there vanishes.
I never understood why you'd want that, and its commonly enabled by default on Linux machines.

The underlying feature is called alternate screen and basically its a feature of your terminal (be it xterm, gnome-term or even your console).

If you want to get rid of it, you have a few options:

Tell each and every program, not to use that feature.

A prime example is the less option -X.
This is useful as a quick ad-hoc solution, but not really feasible for everyday use - You don't really want to (re-)configure every program.

Tell your terminal not to enable this feature.

XTerm has an option located in the Ctrl+Middle mousebutton -Menu and is called Enable Alternate Screen Switching. Turn if off and all programs within will behave nicely.
If you want it for all your xterm windows, you can add something like this to your ~/.Xdefaults:

  XTerm*titeInhibit:  true
  UXTerm*titeInhibit: true

If you're using gnome-terminal, this is not for you. Gnome-terminal simply provides no way to disable this feature. Boo

Lie to your programs and say your terminal doesn't support it.

All (well-behaved) programs check if your terminal supports alternate screens before using them. This information is stored in the system terminfo or termcap database. Whether your system is using termcap or terminfo is an historical thing – Linux/SysV based systems tend to use terminfo, BSDish systems termcap.

This database has an entry for every terminal type your system supports. Your terminal is stored in the $TERM environment variable. Go and check your $TERM value. It is most probably xterm or something similar.

The capabilities for alternate screen are called ti and te in termcap and smcup / rmcup in terminfo. (Yay! for gratuitous differences). What we will be doing, is to override these by placing a suitably modified file in your $HOME.

For terminfo it works like this:

  infocmp -l $TERM > $TERM.src
  vi $TERM.src # remove the smcup= and rmcup= parts till the next ,
  mkdir ~/.terminfo
  tic $TERM.src

This dumps the current entry to a file, and compiles it into a file in ~/.terminfo/ after you modified it.

Termcap just uses plaintext files, so go look into your system termcap file (/usr/share/misc/termcap or similar), and find the entry for your current $TERM. On my system it looks something like this:

  xterm|xterm-color|X11 terminal emulator:\

copy that into ~/.termcap, and add :ti@:te@ at the beginning of the second line to disable these two capabilities. As you can see from my example on FreeBSD this is done by default for xterm and xterm-color.

That should fix it for you.

If you use screen

Lastly, if you are using screen, there is a simpler way to do it. Screen has a built-in feature to edit the termcap/terminfo for programs running inside. Simply add

  termcapinfo xterm* ti@:te@

to your ~/.screenrc (of course replace xterm with your $TERM in use before you start screen)

I hope this lengthy explanation did not bore you too much…

– Sec

posted at: 14:51 | Category: /tidbits | permanent link to this entry | 6 comments (trackback)

Your Comment
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Save my Name and URL/Email for next time
(Note that comments will be rejected unless you enter 42 in the following box: )

powered by blosxom
in 0.00 s