UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 7: Displays and Emulations |
|
||||||||||||||||||||||||||||||||||||
|
Today hundreds of types of displays and terminals are in the marketplace. Every one of them one is different and every one has unique features. They range from basic ASCII terminals to video terminals that can run both ASCII and X. There are smart terminals and dumb terminals, and in many cases the dumb terminals are smarter than the smart terminals.
No matter what kind of terminal you plan to use, you should be able to find a compatible emulator or proper settings that support the various features and sequences that programs use to manipulate the screen. Depending on what you plan to do when you log in to a system, you might not need to worry about how the terminal reacts if the commands you are issuing don't require any specific terminal emulator.
These commands include programs such as who, cat, uname, tail, head, ls, and others that need only a simple linefeed that can endlessly scroll down the screen, similar to a teletype machine that can print on a endless roll of paper. Almost any serial device that displays or prints can be considered a terminal. In the '70s and early '80s, teletype machines worked great as terminals. Although they were slow and used a lot of paper, you could still finish your work.
By now you might be wondering how UNIX can manipulate so many different types of terminals with different features and different control commands. Or in more basic terms, why does the clear command work on one terminal and not on another?
There are two parts to UNIX that make terminals emulate properly: a database and a subroutine library. The database describes the capabilities that are supported on the terminal, and the subroutine library is used to query the database to use the capabilities that are stored there. When you put these together, they make what you know today as the termcap file (named for terminal capabilities ). Over the years the termcap file has grown extremely large. In the AT&T flavors of UNIX, termcap was turned into a database called terminfo. Instead of one large file that holds everything, each terminal description is compiled and stored in a separate file. When programs make use of the terminfo files, they reference the environment variable TERM to figure out what the terminal type is. After this is known, they can go to the database and get the proper database definition for the terminal that you are using.
Administrators need to be able to set the correct terminal type and know which one to use.
Flavor: BSD
The BSD version uses the termcap file that is stored in /etc/termcap. A typical termcap entry has the name of the terminal and any alias names for it. The following lines indicate the special features and the settings for it:
d0|vt100|vt100-am|vt100am|dec vt100:\ :do=^J:co#80:li#24:cl=50\E[;H\E[2J:sf=5\ED:\ :le=^H:bs:am:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\ :ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\ :md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\E[24;1H:\ :rf=/usr/share/lib/tabset/vt100:\ :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\ :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\ :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=5\EM:vt#3:xn:\ :sc=\E7:rc=\E8:cs=\E[%i%d;%dr:
If this entry was not already in the termcap file, it needs only to be appended to the bottom of the file. There are no daemons to restart--a query is sent to the file whenever the environment variable TERM is referenced.
Here is a partial list of definitions in the vt100 entry. On BSD systems, consult the termcap (5) man pages for a more complete listing.
do moves the cursor down n lines
up moves the cursor up n lines
If you want to know which terminals your termcap currently supports, you can use the following command to display all the available entries in your /etc/termcap file:
rocket 1% cat termcap | egrep -v '(#|=)' | cut -d"|" -f2 | more
The command processes ( cat) through a termcap file, stripping out ( egrep -v ) anything with a # character and a = sign in it. It then displays the second field ( cut) that is delimited by a vertical bar ( |). The first field of the entry is usually an abbreviated name, whereas the second field is generally always more descriptive. Because the file holds many entries, pipe it to more so you can easily read all the entries. The file then displays all the entries in a format that you can easily read:
dumb switch ansi sun w50 xterm teletec
Flavor: AT&T
Syntax:
tic file
On the AT&T side, there is an entry similar to the type of database entries found in the termcap. Each entry is a file for the terminal that it represents. After the entry is made into the terminfo file, it is compiled with tic. The terminfo compiler creates a binary representation of the database description and places it in the appropriate terminfo directory under /usr/lib/terminfo.
Here is one type of entry for an ANSI terminal that needs to be compiled into the terminfo database:
# vi newansi
newansi|ansi 6502, am, cols#80, it#8, lines#24, clear=\E[H\E[2J$<50>, cub1=\E[D, cud1=\E[B, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, cuu1=\E[A, el=\E[K, home=\E[H, ht=^I,
This is a short entry by some standards. Most can be as many as 20 lines of settings, depending on the complexity of the terminal. This one is pretty basic by comparison. What follows is a short list of variables that are used within the terminfo file. You should see some similarities with the termcap file entries:
am terminal has automatic margins
cols number of columns in a line
it number of spaces for the tab setting
lines number of lines on a screen
clear clear the screen and home the cursor
cup move to row #1 column #2
home home the cursor
ht hardware tab stop
Many more variables are available and definable. Check your terminfo man pages for a list of all the settings that are available on your system.
Now you have an entry called newansi that can be compiled into the terminfo database. Before doing so, run an integrity check on the entry to verify that everything is valid and in the proper format. To do this, use the terminfo compiler ( tic) with the -c option.
# tic -c newansi
If there are errors in the entry, tic attempts to figure out what the error is and where it is located. If everything runs successfully, nothing is displayed to STDOUT. When the file checks out clean, run tic with no options to compile it into place.
# tic newansi
It almost appears as if nothing happened, but if you look into the terminfo directory, you should see new entries for the file you just compiled.
The terminfo directory is made up of subdirectories that are named after the first letter of the terminfo files in the database. Therefore, the compiled newansi file can be found in the directory /usr/lib/terminfo/n:
# ls -l /usr/lib/terminfo/n*
-rw-r--r-- 1 root sys 12 Jun 13 1997 net -rw-r--r-- 1 root sys 12 Jun 13 1997 network -rw-r--r-- 1 root daemon 982 Nov 29 12:11 newansi
# file /usr/lib/terminfo/n/newansi /usr/lib/terminfo/n/newansi: Compiled Terminfo Entry
If you want to use advanced features to manipulate the screen, terminals function properly only when they have an entry in the database.
The newer terminals on the market today can emulate multiple types of terminals. The Wyse60 ASCII terminal supports vt100, vt220, wyse60, and other types. If this is the case with your terminal, set up the terminal to support one of the entries already available in termcap or terminfo.
If you receive a new terminal from a manufacturer that is not listed in the termcap file, check the documentation. If it is not documented anywhere, you can do several things:
Email the manufacturer. In many cases the vendor can email the entries back to you. (In many instances, manufacturers use the address support@[manufacturer's name].com or have an alias set up to get to technical support.)
nCall the manufacturer. You might be able to get the entry faxed to you. However, finding someone at the manufacturer who knows what a terminal entry is can be a problem from time to time. Tell them you need to speak to someone familiar with UNIX. They don't even have to be in technical support. If you can reach someone with some UNIX knowledge, often they can relay what you are looking for more quickly and easily than you can by trying to describe it to someone who is UNIX illiterate.
Check the Web. If you have acquired a terminal by some other means, and it has no documentation or the vendor is out of business, your last resort is to check for Web sites that mention either the terminal or termcap/terminfo entries. You can also check the Terminfo/Termcap Resource Web page at http://tuxedo.org/~esr/terminfo.
Posting to the Internet. If the entry still cannot be found, try to post a message into the comp.sys.unix Usenet newsgroup or one of the other related newsgroups. Someone might have the entry on his or her system or know how to build one from scratch.
Try a standard entry. You can see whether one of the standard entries works with your terminal. Your best chances are probably with ANSI, vt100, vt220, wyse, or xterm.
Man pages:
termcap, terminfo
World Wide Web:
Terminfo/Termcap Resource-- http://tuxedo.org/~esr/terminfo
UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 7: Displays and Emulations |
|
||||||||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.