Terminals differ. Manufacturers produce a variety of terminals, each one including a particular set of features for a certain price. There are new terminals and old, smart terminals and dumb ones, terminals with big screens and terminals with small screens, printing terminals and video displays, and terminals with all sorts of special features.
In the late 1970s, Bill Joy created the text editor at U.C. Berkeley. Like all screen-oriented editors, vi uses the terminal screen non-sequentially. A program performing non-sequential output does not just print character after character, but must manipulate the text that was sent before, scroll the page, move the cursor, delete lines, insert characters, and more. While it would be possible to keep redrawing the screen in its entirety, many features are provided in hardware or firmware by the terminal itself, and save too much time and trouble to be ignored.
The first version of vi was written specifically for Lear Siegler ADM3a terminals. vi was such an improvement over line-oriented editors that there was great demand to port vi to other brands of terminals. The problem was that each terminal had different features and used different control codes to manipulate the features that they did have in common.
Rather than write separatefor each terminal type, Bill Joy did something very clever, which all UNIX users now take for granted. He wrote a version of vi with generic commands to manipulate the screen instead of hardcoding the control codes and dimensions for a particular terminal.
The generic terminal-handling mechanism Joy came up with had two parts: a database describing the capabilities of each of the terminals to be supported, and a subroutine library that allows programs to query that database and to make use of the capability values it contains. Both the library and the database were given the name termcap, which is short for terminal capabilities.
At this point, users take for granted the fact that you can use just about any terminal with a UNIX system and use screen-oriented programs like vi without any problem. But it is really quite remarkable!
The termcap database is contained in a single text file, which grew quite large over the years to include descriptions of hundreds of different terminals. To improve performance, AT&T later introduced a database called terminfo, which stores terminal descriptions, in compiled form, in a separate file for each terminal.
If a program is designed to use termcap or terminfo, it queries an environment variable calledto determine the terminal type, then looks up the entry for that terminal in the terminal database, and reads the definition of any capabilities it plans to use into external variables. Programs that use termcap or terminfo range from screen editors like vi and , which use the complete terminal description, to a program like , which needs to know only one capability (the escape sequence to clear the screen). Other programs include , pg, rogue, , ul, and .
- from O'Reilly & Associates' termcap & terminfo, Chapter 1