Fixing terminfo so that terminal applications like vi(1) restore the screen

Ever noticed in Solaris that when you finish using vi(1) the terminal screen is not restored? Similarly true for applications like screen(1) and prstat(1M).

This was irritating me somewhat a few months ago but I’ve only now just logged bug 6569261 (xterm, xtermc, xterm-color: smcup/rmcup definitions are incorrect/missing) on it.

Essentially the problem is that the smcup and rmcup definitions don’t work with our gnome-terminal and xterm implementations.

terminfo(4) defines smcup and rmcup as follows:

exit_ca_mode       rmcup  te       String to end programs
that use cup
enter_ca_mode      smcup  ti       String to begin programs
that use cup

These sequences are typically used by terminal applications that control the cursor (eg vi). smcup switches to an alternate screen buffer, rmcup switches back.

The practical effect of this is that the scrolling screen buffer is replaced by a non-scrolling screen buffer when running vi and restored when vi exits.

The rmcup/smcup terminfo descriptions fail to work on Solaris xterm and gnome-terminal implementations. The scolling buffer is not restored and, in some cases, strange escape sequences are seen (eg mysterious ‘0’ characters).

The Solaris xtermc and xterm-color terminfo defines:


These escape sequences don’t make much sense for xterm. The xterm terminfo has nothing for rmcup/smcup.

The Sun Freeware terminfo definitions are more as expected:

xterm-color rmcup=\E[2J\E[?47l\E8,

For ‘standard’ xterm: smcup saves the cursor and switches to the alternate screen buffer; rmcup clears the screen, returns to the normal screen buffer and restores the cursor position.

xterm       rmcup=\E[?1049l

The 1049 sequence is a XFree addition which our xterm doesn’t appear to support. Our current gnome-terminal (snv_65) does support this sequence.

xtermc      rmcup=\E@0\E[?4r

This is as broken as our definition.

The workaround is to define smcup and rmcup appropriately. Here’s one way to fix it:

  1. mkdir $HOME/terminfo
  2. TERM=xterm infocmp > xterm.src
  3. Edit xterm.src and add/change rmcup and smcup:
    rmcup=\E[2J\E[?47l\E8, smcup=\E7\E[?47h,
    every entry must be terminated in a comma (,).
  4. TERMINFO=$HOME/terminfo tic xterm.src
  5. TERMINFO=$HOME/terminfo TERM=xterm xterm

You should now find that your scrolling terminal window is retored after ‘fixed’ window terminal applications finish.

Leave a comment


  1. Nice! Another thing that gets really annoying is that pageup/pagedown keys don’t work in xterms with irssi inside gnu screen… but they work fine in firefox, for example. If you disable the numlock then you can use 9 and 3 as pagup/pagedown, but still the proper pageup/pagedown keys don’t work, this happens only under solaris and I still have to figure out why :/

  2. Hmmm… this is in the eye of the beholder. I for one much prefer the current Solaris behaviour and am always irritated when I work under Linux or BSD, and have to cat or tail the file I’ve just vi’ed. 😦

  3. Peter Eriksson

     /  June 14, 2007

    Definitely eye of the beholder – I personally really hate using tools that remove the information on the screen just because I exit it (prime example: Running “man foo” to get information about something, and then having it removed from ones eyes when one exit man…). If I want to clear my terminal window I’ll do that myself, thankyou… 🙂

  4. Peter Harvey

     /  November 8, 2007

    Fixed in build 76 by my colleague Brian … and it kicked off quite a passionate discussion internally 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • Sporadic tweets from me

  • Tags of interest

  • Categories

  • Advertisements
%d bloggers like this: