Introduction to Termcap

Why Termcap? A Background

Computer users typically interact with the computer through a display terminal and keyboard. The terminal is separate from the computer and connected by a cable. To display information on the screen, data must be sent to the terminal. To input data to the computer through the keyboard, the computer receives data from the terminal. The data is sent and received as a series of numbers whose values can range from 0 to 255. The range of numbers can also be half that much; from 0 to 127. The terminal and computer must have an agreed upon meaning for each number.

Displaying Text

Each character on the keyboard has a number assigned to it. For example, pressing the "A" key causes the number 65 to be sent to the computer. Conversely, if the computer sends a 65 to the terminal, an "A" will appear on the terminal screen. This association between the number 65 and the letter "A" is determined by a standard known as ASCII (American Standard Code for Information Interchange). Practically all terminals conform to this standard.

When an application program displays data on the screen (such as a person's name) it sends the numbers necessary to represent the desired alphabetic characters. The characters are displayed on the screen at the location indicated by the cursor.

Control Characters

In addition to printing simple text, the computer instructs the terminal to perform a variety of functions. Like the letters of the alphabet, these additional functions are also represented by numeric codes. These numeric codes are called control characters or control codes.

For example, ASCII defines code number 8 as a backspace. If the computer sends the value 8 to the terminal, it will back up one character. If the backspace" key on the keyboard were pressed, the computer would receive the value 8.

Escape Sequences

There are many more functions that terminals can perform than there are available control codes. Therefore, many terminal functions are invoked by sending the terminal special sequences of numbers that are recognized by the terminal. These are known as "control sequences". A control sequence usually begins with the control code 27, known as the ESCAPE character. This alerts the terminal that a special function is being requested (such as "clear the screen"). The next number or numbers sent by the computer further describe the desired function. The term "escape sequence" is frequently used instead of "control sequence." While the codes for text characters are standard, escape sequences are not standard. Different models of terminals understand different escape sequences.

For example, a programmer wishing to clear the screen would not know what escape sequence to send to the terminal unless it was known what kind of terminal was being used. There are several solutions to this problem, the most effective being the terminal database.

The terminal database contains the needed information for many different terminals. Once an application determines the kind of terminal being used, it looks up that terminal in the database and reads the necessary information about it. This information may include the size of the screen (rows and columns) and the necessary escape sequences to perform various functions, such as clear screen. Application programs using terminal databases do not need not be updated as new types of terminals are introduced. Once an entry describing the new terminal is added to the database, the application will adapt to it automatically. This type of database is known as "termcap" (for "terminal capabilities").