Next Previous Contents

15. Terminfo and Termcap (detailed)

15.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 different commands (some of which take numeric parameters).

The terminfo abbreviations are usually longer than those of termcap and thus it's easier to guess what they mean. The manual pages for terminfo are more detailed (and include the old termcap abbreviations). Thus, unless you are already committed to termcap, you should use the terminfo files.

15.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, by a single command, be both converted to terminfo source and then compiled. Thus you may get by without having any terminfo source since the termcap source can create the compiled terminfo database.

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. Unless this terminfo data base happens to be located where every program that needs it expects to find it, then the environment variable TERMINFO should be set to the path to this database. Example: TERMINFO=/usr/share/terminfo

The source code you use may reside in /etc/termcap and/or in terminfo.src (or another name). 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 on your computer 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 http://sagan.earthspace.net/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 the terminfo entry for the terminal you are using (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 (or might need in the future). Don't delete any of the termcaps for a "Linux terminal" (the console) or the xterm ones if you use X-Windows. The terminal type "dumb" may be needed 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 few seconds.

15.3 Modifying Terminfo Files

Some of the supplied terminfo entries can be improved. For example, most terminals have a graphics character set which may be used for drawing boxes with solid lines (not dashed lines). If you see dashed lines in application programs like minicom, then perhaps the reason is that the graphics capability was not put into the terminfo file. You may add it by finding out what symbols to use from the manual (in this case you must assign values to: enacs, rmacs, and smacs) and then edit the source file. Then by using "tic" you may compile it. "tic" should automatically put the compiled terminfo file in the correct directory reserved for it.

If you would like to find a better terminfo than the one supplied, you might try searching the Internet (but what you find may be worse). If your new terminfo entry is better than the old one and it seems stable (you've used it for a while with no problems) then you should send a copy to the maintainer of terminfo as noted at the start of the source file for terminfo (or termcap).

15.4 Init String

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. An initialization string is not automatically sent to the terminal to initialize it. One might expect that the getty program should do this but if it did, one could make a change to the set-up at the terminal and this change wouldn't be implemented because the init string would automatically cancel it. You must use a command given on the command line (or in a shell script) to send the init string such. Such commands are: "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).

15.5 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 for this or 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).

15.6 Terminfo/Termcap Documents


Next Previous Contents