tput (1) Linux Manual Page
NAME
tput, reset – initialize a terminal or query terminfo database
SYNOPSIS
tput [-Ttype] capname [parameters]
tput [-Ttype] [-x] clear
tput [-Ttype] init
tput [-Ttype] reset
tput [-Ttype] longname
tput -S <<
tput -V
DESCRIPTION
The tput utility uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell (see sh(1)), to initialize or reset the terminal, or return the long name of the requested terminal type. The result depends upon the capability’s type:
-
- string
-
tputwrites the string to the standard output. No trailing newline is supplied. - integer
-
tputwrites the decimal value to the standard output, with a trailing newline. - boolean
-
tputsimply sets the exit code (0for TRUE if the terminal has the capability,1for FALSE if it does not), and writes nothing to the standard output.
Before using a value returned on the standard output, the application should test the exit code (e.g., $?, see sh(1)) to be sure it is 0. (See the EXIT CODES and DIAGNOSTICS sections.) For a complete list of capabilities and the capname associated with each, see terminfo(5).
Options
-S- allows more than one capability per invocation of
tput. The capabilities must be passed totputfrom the standard input instead of from the command line (see example). Only one capname is allowed per line. The-Soption changes the meaning of the0and1boolean and string exit codes (see the EXIT CODES section). - Because some capabilities may use string parameters rather than numbers,
tputuses a table and the presence of parameters in its input to decide whether to usetparm(3X), and how to interpret the parameters. -Ttype- indicates the type of terminal. Normally this option is unnecessary, because the default is taken from the environment variable
TERM. If-Tis specified, then the shell variablesLINESandCOLUMNSwill also be ignored. -V- reports the version of ncurses which was used in this program, and exits.
-x- do not attempt to clear the terminal’s scrollback buffer using the extended “E3” capability.
Commands
A few commands (init, reset and longname) are special; they are defined by the tput program. The others are the names of capabilities from the terminal database (see terminfo(5) for a list). Although init and reset resemble capability names, tput uses several capabilities to perform these special functions.
- capname
- indicates the capability from the terminal database.
- If the capability is a string that takes parameters, the arguments following the capability will be used as parameters for the string.
- Most parameters are numbers. Only a few terminal capabilities require string parameters;
tputuses a table to decide which to pass as strings. Normallytputusestparm(3X) to perform the substitution. If no parameters are given for the capability,tputwrites the string without performing the substitution. init- If the terminal database is present and an entry for the user’s terminal exists (see
-Ttype, above), the following will occur:-
- (1)
- first,
tputretrieves the current terminal mode settings for your terminal. It does this by successively testing-
.IP • 4 the standard error,
.IP • 4 standard output,
.IP • 4 standard input and
.IP • 4 ultimately “/dev/tty”
- to obtain terminal settings. Having retrieved these settings,
tputremembers which file descriptor to use when updating settings. - (2)
- if the window size cannot be obtained from the operating system, but the terminal description (or environment, e.g.,
LINESandCOLUMNSvariables specify this), update the operating system’s notion of the window size. - (3)
- the terminal modes will be updated:
-
.IP • 4 any delays (e.g., newline) specified in the entry will be set in the tty driver,
.IP • 4 tabs expansion will be turned on or off according to the specification in the entry, and
.IP • 4 if tabs are not expanded, standard tabs will be set (every 8 spaces).
- (4)
- if present, the terminal’s initialization strings will be output as detailed in the
terminfo(5) section on Tabs and Initialization, - (5)
- output is flushed.
- If an entry does not contain the information needed for any of these activities, that activity will silently be skipped.
reset- This is similar to
init, with two differences:-
- (1)
- before any other initialization, the terminal modes will be reset to a “sane” state:
-
.IP • 4 set cooked and echo modes,
.IP • 4 turn off cbreak and raw modes,
.IP • 4 turn on newline translation and
.IP • 4 reset any unset special characters to their default values
- (2)
- Instead of putting out initialization strings, the terminal’s reset strings will be output if present (
rs1,rs2,rs3,rf). If the reset strings are not present, but initialization strings are, the initialization strings will be output.
- Otherwise,
resetacts identically toinit. longname- If the terminal database is present and an entry for the user’s terminal exists (see
-Ttype above), then the long name of the terminal will be put out. The long name is the last name in the first line of the terminal’s description in theterminfodatabase [seeterm(5)].
Aliases
tput handles the clear, init and reset commands specially: it allows for the possibility that it is invoked by a link with those names.
If tput is invoked by a link named reset, this has the same effect as tput reset. The tset(1) utility also treats a link named reset specially.
Before ncurses 6.1, the two utilities were different from each other:
.IP • 4 tset utility reset the terminal modes and special characters (not done with tput).
.IP • 4 On the other hand, tset‘s repertoire of terminal capabilities for resetting the terminal was more limited, i.e., only reset_1string, reset_2string and reset_file in contrast to the tab-stops and margins which are set by this utility.
.IP • 4 The reset program is usually an alias for tset, because of this difference with resetting terminal modes and special characters.
With the changes made for ncurses 6.1, the reset feature of the two programs is (mostly) the same. A few differences remain:
.IP • 4 The tset program waits one second when resetting, in case it happens to be a hardware terminal.
.IP • 4 The two programs write the terminal initialization strings to different streams (i.e., the standard error for tset and the standard output for tput).
-
Note:although these programs write to different streams, redirecting their output to a file will capture only part of their actions. The changes to the terminal modes are not affected by redirecting the output.
If tput is invoked by a link named init, this has the same effect as tput init. Again, you are less likely to use that link because another program named init has a more well-established use.
Terminal Size
Besides the special commands (e.g., clear), tput treats certain terminfo capabilities specially: lines and cols. tput calls setupterm(3X) to obtain the terminal size:
.IP • 4 first, it gets the size from the terminal database (which generally is not provided for terminal emulators which do not have a fixed window size)
.IP • 4 then it asks the operating system for the terminal’s size (which generally works, unless connecting via a serial line which does not support NAWS: negotiations about window size).
.IP • 4 finally, it inspects the environment variables LINES and COLUMNS which may override the terminal size.
If the -T option is given tput ignores the environment variables by calling use_tioctl(TRUE), relying upon the operating system (or finally, the terminal database).
EXAMPLES
tput init- Initialize the terminal according to the type of terminal in the environmental variable
TERM. This command should be included in everyone’s .profile after the environmental variableTERMhas been exported, as illustrated on theprofile(5) manual page. tput -T5620 reset- Reset an AT&T 5620 terminal, overriding the type of terminal in the environmental variable
TERM. tput cup 0 0- Send the sequence to move the cursor to row
0, column0(the upper left corner of the screen, usually known as the “home” cursor position). tput clear- Echo the clear-screen sequence for the current terminal.
tput cols- Print the number of columns for the current terminal.
tput -T450 cols- Print the number of columns for the 450 terminal.
bold=`tput smso` offbold=`tput rmso`- Set the shell variables
bold, to begin stand-out mode sequence, andoffbold, to end standout mode sequence, for the current terminal. This might be followed by a prompt:echo "${bold}Please type in your name: ${offbold}
