home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 5.11 Initializing the Terminal with tset Chapter 5
Setting Up Your Terminal
Next: 6. Shell and Environment Variables

5.12 Initializing the Terminal with tput

The tput program used with terminfo is somewhat equivalent to tset (5.3 , 5.11 ) , but does not have the ability that tset has to determine the terminal type. On the other hand, it allows you to pick out particular terminal capabilities and print out their values or store them into shell variables. [The tcap (41.10 ) program does the same kind of thing for termcap . -JP  ] This allows shell programs to make use of terminal capabilities (41.10 ) such as inverse video or underlining.

By default, tput assumes that you are using the terminal type specified by the TERM (5.10 ) variable. If you want to override the value of TERM , you can specify another terminal type with the -T option. For example:

$ tput -Twy50 ...

In System V Release 3, tput has a keyword option that allows you to reset the terminal by outputting the initialization strings (there are several) from a terminfo description:

$ tput init

The command:

$ tput reset

issues the reset strings from the terminfo entry. If no reset strings are defined, the initialization strings are issued instead, and the command acts exactly like tput init .

In earlier releases of System V, these keywords are not supported, and you must issue multiple tput commands to output each of the initialization or reset strings by name.

The following shell program, contributed by Tony Hansen of AT&T, will do the trick:


# Evaluate and output the iprog capability
eval `tput iprog`
# output the is1 and is2 initialization strings
tput is1
tput is2

# if the terminal supports tabs, set them
# otherwise, disable them
if [ -n "`tput ht`" ]
then stty tabs; tabs -8
else stty -tabs
# output contents of the initialization file, if present
cat -s "`tput if`"
# output the is3 initialization string
tput is3

See your system manuals, or O'Reilly & Associates' termcap & terminfo , for a description of the various initialization capabilities used in this script.

- TOR from O'Reilly & Associates' termcap & terminfo , Chapter 4

Previous: 5.11 Initializing the Terminal with tset UNIX Power Tools Next: 6. Shell and Environment Variables
5.11 Initializing the Terminal with tset Book Index 6. Shell and Environment Variables

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System