41.10 Using terminfo Capabilities in Shell ProgramsThe weakness of the technique described in article 41.9 is that it requires you to hardcode the escape sequences for a particular terminal. If you use more than one kind of terminal, you have to create separate aliases for each one. That's exactly the kind of problem that the termcap and terminfo databases were designed to solve.
For example, a prompt issued by a shell program could be highlighted by the following code using tput :
Capabilities that accept arguments (such as cursor movement sequences) will interpolate values that follow the capability name on the command line. For example, to issue the cursor motion sequence to move to the upper-left corner of the screen (row 0, column 0), you could type:
$ Another case where tput comes in useful is when command sequences accidentally get sent to the screen, leaving output garbled or in a distracting highlight mode. It sometimes happens that a user reads a non-ASCII file, or reads a mail message with a control character accidentally imbedded, and ends up with gibberish. This is often because the sequence for entering an alternate character set has been sent to the terminal, and the screen is no longer readable to the human eye. The user can return to the normal character set two ways: by rebooting the terminal, or by entering tput init ( 5.12 ) on the command line. Using tput , obviously, is much more efficient. - , |
|