Monday, May 18, 2009

Terminal Capabilities


If you are interacting with the system solely through command line input, you have few occasions to encounter the terminal capabilities. As the name implies, terminal capabilities determine what the terminal is capable of. For example, can the terminal move the cursor to a specific spot on the screen?

The terminal capabilities are defined by one of two databases. Older applications generally use termcap, while newer ones use terminfo. For the specifics on each, please see the appropriate man-page. Here I am going to talk about the concept of terminal capabilities and what it means to you as a user.

Within each of these databases is a mapping of the character or character sequence the terminal xxpects for certain behavior. For example, on some terminals, pressing the backspace key sends a Ctrl-? character. On others, Crtl-H is sent. When your TERM environment variable is set to the correct one for your terminal, pressing the backspace key sends a signal to the system which, in turn, tells the application that the backspace characteristic was called. The application is told not just that you pressed the key with the left arrow ( FACE="Symbol">¬) on it. Instead, the application is told that that key was the backspace. It is then up to the application to determine what is to be done.

The key benefit of a system like this is that you do not have to recompile or rewrite your application to work on different terminals. Instead, you link in the appropriate library to access either termcap or terminfo and wait for the capability that OS will send to you. When the application receives that capability (not the key), it reacts accordingly.

There are three types of capabilities. The first capabilities are Boolean, which determine whether that terminal has a particular feature. For example, does the terminal have an extra "status" line? The next type is numeric values. Examples of this capability are the number of columns and lines the terminal can display. In some cases, this may not remain constant, as terminals such as the Wyse 60 can change between 80- and 132-column mode. Last are the string capabilities that provide a character sequence to be used to perform a particular operation. Examples of this would be clearing the line from the current cursor position to the end of the line and deleting the contents of an entire line (with or without removing the line completely).

Despite that there are hundreds of possible capabilities, any given terminal will have only a small subset of capabilities. In addition, many of the capabilities do not apply to terminals, but rather to printers.

Both the termcap and terminfo databases have their own advantages and disadvantages. The termcap database is defined by the file /etc/termcap, an ASCII file that is easily modified. In contrast to this is the terminfo database, which starts out as an ASCII file but must be compiled before it can be used.

The termcap entries can be converted to terminfo with the captoinfo command and then compiled using tic, the terminfo compiler. The tic utility will usually place the compiled version in a directory under /usr/lib/terminfo based on the name of the entry. For example, the ANSI terminal ends up in /usr/lib/terminfo/a and Wyse terminals end up in /usr/lib/terminfo/w.

No comments:

Post a Comment