Next Previous Contents

13. Terminfo and Termcap (detailed)

13.1 Introduction

Terminfo (formerly Termcap) is a database of terminal capabilities and more. For every (well almost) model of terminal it tells application programs what the terminal is capable of doing. It tells what escape sequences (or control characters) to send to the terminal in order to do things such as move the cursor to a new location, erase part of the screen, scroll the screen, change modes, change appearance (colors, brightness, blinking, underlining, reverse video etc.). After about 1980, many terminals supported over a hundred such commands.

13.2 Terminfo Database

The terminfo database is compiled and thus has a source part and a compiled part. The old termcap database has only a source part but this source can be both converted to terminfo source and then compiled by a single command. To see if your terminal (say vt100) is in the terminfo data base type "locate vt100". It may show /usr/lib/terminfo/v/vt100 or /usr/share/terminfo/v/vt100 which are possible locations of the compiled terminfo files. Some older programs may expect it to be in the /etc/terminfo directory.

The source code you use may reside in /etc/termcap and/or in terminfo.src. See the man pages: terminfo(5) or termcap(5) for the format required to create (or modify) these files. The file terminfo.src may be in various locations or it may not be included with your linux distribution. Use the locate command to try to find it. It is available for downloading (under the name termtypes.ti) from locke.ccil.org/~esr/terminfo

Terminfo Compiler (tic)

The data in the source files is compiled with the "tic" program which is capable of converting between termcap format and terminfo format. Thus you can create a compiled terminfo data base from termcap source. The installation program which was used to install Linux probably installed the compiled files on your hard disk so you don't need to compile anything unless you modify /etc/termcap (or terminfo.src ). "tic" will automatically install the resulting compiled files into a terminfo directory ready to be used by application programs.

Look at Your Terminfo

It's a good idea to take a look at your termcap/terminfo entry (source code of course) and read the comments. A quick way to inspect it without comments is to just type "infocmp". But the comments may tell you something special about the terminal such as how you need to set it up so that it will work correctly with the terminfo database.

Deleting Data Not Needed

In order to save disk space, one may delete all of the database except for the terminals types that you have. Don't delete any of the Linux termcaps or the xterm ones if you use X-Windows. The terminal type "dumb" is used when an application program can't figure out what type of terminal you are using. It would save disk space if install programs only installed the terminfo for the terminals that you have and if you could get a termcap for a newly installed terminal over the Internet in a fraction of a second.

13.3 Initialization

Included in the terminfo are often a couple of initialization strings which may be sent to the terminal to initialize it. This may change the appearance of the screen, change what mode the terminal is in, and/or make the terminal emulate another terminal. The initialization strings are not automatically sent to the terminal to initialize it. You must use a command given on the command line (or in a shell script) to do it such as: "tset", "tput init", or "setterm -initialize". Sometimes there is no need to send the init string since the terminal may set itself up correctly when it is powered on (using options/preferences one has set up and saved in non-volatile memory of the terminal).

13.4 TERM Variable

The Environment variable TERM should be set to the type of terminal which you are using. It is normally set by the terminal_type parameter passed to the getty program (look at it in the /etc/inittab file). This name must be in the Terminfo data base. Just type "set" at the command line to see what TERM is set to (or type: tset -q). At a console (monitor) TERM is set to "linux" which is the PC monitor emulating a fictitious terminal model named "linux". Since "linux" is close to a vt100 terminal and many text terminals are also, the "linux" designation will sometimes work as a temporary expedient with a text terminal.

If more than one type of terminal may be connected to the same port (/dev/tty...) (for example, if there is a switch to permit different terminal types to use the same serial port, or if the port is connected to a modem to which people call in from different types of terminals) then TERM needs to be set each time someone connects to the serial port. There is often a query escape sequence so that the computer may ask the terminal what type it is. Another way is to ask the user to type in (or select) the type of terminal s/he is using. You may need to use tset of write a short shell script to handle this.

One way to do this is to use "tset" (see the manual page). tset tries to determine the terminal name of the terminal you are using. Then it looks up the data in terminfo and sends your terminal an init string. It can also set the value of TERM. For example, a user dials in and logs in. The .profile login script is executed which contains within it the following statement: eval `tset -s ?vt100`. This results in: The user is asked if s/he is using a vt100. The user either responds yes or types in the actual terminal type s/he is using. Then tset sends the init string and sets TERM to this terminal name (type).

13.5 Termcap Documents


Next Previous Contents