Andys Terminfo Package

Download from


Full screen text programs under UNIX usually use a code module called 'curses' get keyboard input and to do screen output.

When you run such a program, curses determines what sort of 'terminal' you are running one by looking at the TERM environment variable. Very often this will be vt100, or if you are using a shell in an X Windows window, it will be xterm. If TERM isn't set, the program should fail to run.

Curses then locates the 'terminal information database' by looking for it in the directory specified by the TERMINFO environment variable. If this variable isn't set, it looks in a fixed place, which is often /usr/share/terminfo or /usr/lib/terminfo.

In this database there should be an entry for the type of terminal being used. If not, the program should fail to run.

The terminfo entry describes what escape sequences need to be output to the terminal in order to get it to move the cursor, change colour, erase areas etc.. If the terminfo entry is wrong, then the screen is likely to be corrupted as the program runs. If the TERM variable is wrong, the wrong terminfo entry will be used and the effect can be the same.

Common pitfalls

Things to check if your curses program fails to run :-

Default level of support

The terminfo database supplied on many UNIXes is rather limited.

For example, despite the fact that virtually every VT100 compliant terminal you can lay your hands on supports color, virtually no vt100 terminfo database entry supports this. This is true of AIX, HP-UX and SunOS.

Even if you argue that VT100 doesn't support color, there really ought to be a vt100-color database entry which adds the necessary extras.

There is a precedent for this sort of thing. X terminals don't support color, and so the xterm terminfo database entry doesn't support color. However, there is are color_xterm, nxterm and similar programs which do. Accordingly, forward thinking UNIXes (ie: Linux) include an xterm with color, and/or an xterm-color terminfo database entry.

The basic problem is that most UNIX vendors have no enthusiasm for making full screen text mode applications work well. Perhaps the view is that X Windows replaces all of that.

In fact the trend is that things will get worse. IBM replaced their excellent 'hft' High Function Terminal, with a stripped down functionality 'lft' Low Function Terminal. Under AIXwindows you get an excellent aixterm terminal, with full color and extensive keyboard support. Unfortunately, IBM is moving towards the new CDE environment. The new dtterm program supplied with CDE has no color and naff keyboard support. I wonder if Gnome/KDE will provide better tools.

Improving level of support

The trick is to use the infocmp program to extract the terminfo database entry for a given terminal type, and then to enhance it. You can then use tic to compile up an enhanced terminfo database entry.

This I did on my Linux system. After some annotation, it looks like :-

	vt100|vt100-am|Digital VT100,
	# Size
		cols#80, lines#24,
	# Automatic margins
	# Safe to move in standout modes
	# Ignores new-line after 80 columns
	# Padding won't work, need XON/XOFF
	# Virtual terminal number
	# Alternate character set mapping of glyph to characters
	# Clear screen and home cursor
	# Change scroll region
	# Cursor motion
		cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=^J, 
		cuf=\E[%p1%dC, cuf1=\E[C$<2>, 
		cup=\E[%i%p1%d;%p2%dH$<5>, cuu=\E[%p1%dA, 
		cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>, el1=\E[1K$<3>,
		home=\E[H, ht=^I, 
	# Set tabstops, tabstops initially every 8 chars, clear all tabstops
	# Keycodes
		ka1=\EOq, ka3=\EOs, kb2=\EOr, 
		kbs=^H, kc1=\EOp, kc3=\EOn, kcub1=\EOD, kcud1=\EOB, 
		kcuf1=\EOC, kcuu1=\EOA, kent=\EOM, kf0=\EOy, 
		kf1=\EOP, kf10=\EOx, kf2=\EOQ, kf3=\EOR, kf4=\EOS, 
		kf5=\EOt, kf6=\EOu, kf7=\EOv, kf8=\EOl, kf9=\EOw, 
	# Set reverse video
	# Reset terminal to known modes
	# Scroll text up
	# Reverse scroll
	# Set graphics rendition (combinations of bright, uline etc.)
	# Set/reset standout
		smso=\E[7m$<2>,	rmso=\E[m$<2>, 
	# Set/reset underline
		smul=\E[4m$<2>, rmul=\E[m$<2>, 
	# Enable/set/reset alternate char set
		enacs=\E(B\E)0, smacs=^N, rmacs=^O, 
	# Set/reset automatic margin mode
		smam=\E[?7h, rmam=\E[?7l,
	# Start/end keypad transmit mode
		smkx=\E[?1h\E=,	rmkx=\E[?1l\E>,
	# Save/restore cursor position
		sc=\E7, rc=\E8,

If you place this in a file, and add the following extra stuff, you have a way of making the terminfo entry for an enhanced colour VT100 terminal :-

	vt100-color|vt100-colour|VT100 with ANSI colour support,
	# 8 colours, 8x8 foreground/background pairs
		colors#8, pairs#64, 
	# ANSI set-background and set-foreground
		setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 
	# Set-background and set-foreground
		setb=\E[%p1%{40}%+%dm, setf=\E[%p1%{30}%+%dm, 
	# Original pair (ie: default colour is white on black)
	# Background erase
	# Use of colour is incompatible with use of standout and underline
	# Everything else as from vt100 definition

The op entry is necessary. Colour pair 0, ie: the 'original pair', is defined to mean white on black, and the terminal is assumed to be white on black before the curses program starts. When the program finishes, op is written to turn the terminal back to its initial white on black state. Also, when the curses program wants to set white on black, it will output the op sequence, rather than the set-foreground and set-background sequences. If the op entry is missing, some curses implementations assume the terminal cannot support colour, even if the set-foreground and set-background sequences are defined.

The bce entry says that areas of the screen which are cleared are cleared to the current background colour. This is pretty much the norm for PC displays and most VT100 emulators, but may not have been the case for the original VT100.

The enhanced terminfo entry can be compiled using tic (or tic_colr on HP-UX).

However, mere users aren't usually allowed to modify or add to the default system terminfo database. So to avoid this problem, you can create a directory of your own, to hold your own personal database. Set TERMINFO to point there, and then run tic.

Compiled terminfo database entries appear to be compatible between Linux, HP-UX and SunOS, but of course, just to be awkward, AIX Extended Curses is different.

AIX Extended Curses verses AIX Curses

TH under AIX is implemented using Curses, but unfortunately AIX has two kinds :-

  1. AIX Extended Curses. This was IBMs original answer to the question 'how do you add colour support and other features to basic Curses', in the days before it was all standardised. Of course, everyone else (SunOS, Linux, HP-UX etc.) all decided to do it another way, the POSIX way. Supported on 4.x and 5.x (32 bit compilation mode only), although considered 'legacy' from AIX 4.3 on. Older AIX programs, or programs which must run on earlier AIX versions will be compiled and linked with AIX Extended Curses. Programs #include <curXX.h> headers and link with -lcur -lcurses when using AIX Extended Curses.
  2. AIX Curses. Supported on AIX 4.3 and onwards (including 64 bit compilation mode of AIX 5.x). This is basically IBM falling in line with the rest of the industry. Programs #include <curses.h> and link with -lcurses when using standard Curses.

The AIX aixterm terminfo definition, as shipped with AIX 4.3 and AIX 5.0 is broken. It omits the bce entry, and incorrectly encodes the op original pair as green on black rather than the white on black it should be. The old AIX Extended Curses implementation doesn't seem to mind these errors, but the newer AIX Curses implementation ends up drawing swathes of background in the wrong colour, and anything which should be white on black comes out green on black.

Accordingly, this TERMINFO package will need to override the standard aixterm entry, but doesn't yet.

The package

You can enhance your terminal support by going through the steps explained above, or you can use my package.

Andys Terminfo Package consists of some files (including this HTML page) which you can put in a directory below your home directory, called ~/terminfo.

You then arrange that whenever you fire up a C shell (csh or tcsh), or one is fired within a window you start, that the terminal definitions provided by the system get enhanced. Add the following to ~/.cshrc or ~/.tcshrc :-

# Try to enhance terminal
source ~/terminfo/setup.csh

setup.csh is a little script which looks at the current system type and current terminal type. If it reckons it has a better terminal definition it can use, it modifies the TERMINFO and TERM environment variables.

Or if you use a Bourne style shell (bsh, sh, ksh, pdsh, bash, ash, zsh etc.), then you would add the following to your ~/.kshrc, ~/.bashrc, ~/.zshrc.

Unfortunately this doesn't cover some of the shells, such as sh, which doesn't read a configuration file when the shell is started, only a log in time. So in this case we must fall back to modifying the per-login ~/.profile instead.

# Try to enhance terminal
. ~/terminfo/

The advantage of getting the setup script run at every shell start is that the terminal is fixed up even if you run a nested shell within an xterm, dtterm or whatever.

This page was written by the TERMINFO author, Andy Key