1tput(1) General Commands Manual tput(1)
2
3
4
6 tput, reset - initialize a terminal or query terminfo database
7
9 tput [-Ttype] capname [parameters]
10 tput [-Ttype] [-x] clear
11 tput [-Ttype] init
12 tput [-Ttype] reset
13 tput [-Ttype] longname
14 tput -S <<
15 tput -V
16
18 The tput utility uses the terminfo database to make the values of ter‐
19 minal-dependent capabilities and information available to the shell
20 (see sh(1)), to initialize or reset the terminal, or return the long
21 name of the requested terminal type. The result depends upon the capa‐
22 bility's type:
23
24 string
25 tput writes the string to the standard output. No trailing
26 newline is supplied.
27
28 integer
29 tput writes the decimal value to the standard output, with a
30 trailing newline.
31
32 boolean
33 tput simply sets the exit code (0 for TRUE if the terminal has
34 the capability, 1 for FALSE if it does not), and writes nothing
35 to the standard output.
36
37 Before using a value returned on the standard output, the application
38 should test the exit code (e.g., $?, see sh(1)) to be sure it is 0.
39 (See the EXIT CODES and DIAGNOSTICS sections.) For a complete list of
40 capabilities and the capname associated with each, see terminfo(5).
41
42 Options
43 -S allows more than one capability per invocation of tput. The ca‐
44 pabilities must be passed to tput from the standard input in‐
45 stead of from the command line (see example). Only one capname
46 is allowed per line. The -S option changes the meaning of the 0
47 and 1 boolean and string exit codes (see the EXIT CODES sec‐
48 tion).
49
50 Because some capabilities may use string parameters rather than
51 numbers, tput uses a table and the presence of parameters in its
52 input to decide whether to use tparm(3X), and how to interpret
53 the parameters.
54
55 -Ttype indicates the type of terminal. Normally this option is unnec‐
56 essary, because the default is taken from the environment vari‐
57 able TERM. If -T is specified, then the shell variables LINES
58 and COLUMNS will also be ignored.
59
60 -V reports the version of ncurses which was used in this program,
61 and exits.
62
63 -x do not attempt to clear the terminal's scrollback buffer using
64 the extended “E3” capability.
65
66 Commands
67 A few commands (init, reset and longname) are special; they are defined
68 by the tput program. The others are the names of capabilities from the
69 terminal database (see terminfo(5) for a list). Although init and re‐
70 set resemble capability names, tput uses several capabilities to per‐
71 form these special functions.
72
73 capname
74 indicates the capability from the terminal database.
75
76 If the capability is a string that takes parameters, the argu‐
77 ments following the capability will be used as parameters for
78 the string.
79
80 Most parameters are numbers. Only a few terminal capabilities
81 require string parameters; tput uses a table to decide which to
82 pass as strings. Normally tput uses tparm(3X) to perform the
83 substitution. If no parameters are given for the capability,
84 tput writes the string without performing the substitution.
85
86 init If the terminal database is present and an entry for the user's
87 terminal exists (see -Ttype, above), the following will occur:
88
89 (1) first, tput retrieves the current terminal mode settings
90 for your terminal. It does this by successively testing
91
92 • the standard error,
93
94 • standard output,
95
96 • standard input and
97
98 • ultimately “/dev/tty”
99
100 to obtain terminal settings. Having retrieved these set‐
101 tings, tput remembers which file descriptor to use when up‐
102 dating settings.
103
104 (2) if the window size cannot be obtained from the operating
105 system, but the terminal description (or environment, e.g.,
106 LINES and COLUMNS variables specify this), update the oper‐
107 ating system's notion of the window size.
108
109 (3) the terminal modes will be updated:
110
111 • any delays (e.g., newline) specified in the entry will
112 be set in the tty driver,
113
114 • tabs expansion will be turned on or off according to
115 the specification in the entry, and
116
117 • if tabs are not expanded, standard tabs will be set
118 (every 8 spaces).
119
120 (4) if present, the terminal's initialization strings will be
121 output as detailed in the terminfo(5) section on Tabs and
122 Initialization,
123
124 (5) output is flushed.
125
126 If an entry does not contain the information needed for any of
127 these activities, that activity will silently be skipped.
128
129 reset This is similar to init, with two differences:
130
131 (1) before any other initialization, the terminal modes will be
132 reset to a “sane” state:
133
134 • set cooked and echo modes,
135
136 • turn off cbreak and raw modes,
137
138 • turn on newline translation and
139
140 • reset any unset special characters to their default
141 values
142
143 (2) Instead of putting out initialization strings, the termi‐
144 nal's reset strings will be output if present (rs1, rs2,
145 rs3, rf). If the reset strings are not present, but ini‐
146 tialization strings are, the initialization strings will be
147 output.
148
149 Otherwise, reset acts identically to init.
150
151 longname
152 If the terminal database is present and an entry for the user's
153 terminal exists (see -Ttype above), then the long name of the
154 terminal will be put out. The long name is the last name in the
155 first line of the terminal's description in the terminfo data‐
156 base [see term(5)].
157
158 Aliases
159 tput handles the clear, init and reset commands specially: it allows
160 for the possibility that it is invoked by a link with those names.
161
162 If tput is invoked by a link named reset, this has the same effect as
163 tput reset. The tset(1) utility also treats a link named reset spe‐
164 cially.
165
166 Before ncurses 6.1, the two utilities were different from each other:
167
168 • tset utility reset the terminal modes and special characters (not
169 done with tput).
170
171 • On the other hand, tset's repertoire of terminal capabilities for
172 resetting the terminal was more limited, i.e., only reset_1string,
173 reset_2string and reset_file in contrast to the tab-stops and mar‐
174 gins which are set by this utility.
175
176 • The reset program is usually an alias for tset, because of this
177 difference with resetting terminal modes and special characters.
178
179 With the changes made for ncurses 6.1, the reset feature of the two
180 programs is (mostly) the same. A few differences remain:
181
182 • The tset program waits one second when resetting, in case it hap‐
183 pens to be a hardware terminal.
184
185 • The two programs write the terminal initialization strings to dif‐
186 ferent streams (i.e., the standard error for tset and the standard
187 output for tput).
188
189 Note: although these programs write to different streams, redirect‐
190 ing their output to a file will capture only part of their actions.
191 The changes to the terminal modes are not affected by redirecting
192 the output.
193
194 If tput is invoked by a link named init, this has the same effect as
195 tput init. Again, you are less likely to use that link because another
196 program named init has a more well-established use.
197
198 Terminal Size
199 Besides the special commands (e.g., clear), tput treats certain ter‐
200 minfo capabilities specially: lines and cols. tput calls setupterm(3X)
201 to obtain the terminal size:
202
203 • first, it gets the size from the terminal database (which generally
204 is not provided for terminal emulators which do not have a fixed
205 window size)
206
207 • then it asks the operating system for the terminal's size (which
208 generally works, unless connecting via a serial line which does not
209 support NAWS: negotiations about window size).
210
211 • finally, it inspects the environment variables LINES and COLUMNS
212 which may override the terminal size.
213
214 If the -T option is given tput ignores the environment variables by
215 calling use_tioctl(TRUE), relying upon the operating system (or fi‐
216 nally, the terminal database).
217
219 tput init
220 Initialize the terminal according to the type of terminal in the
221 environmental variable TERM. This command should be included in
222 everyone's .profile after the environmental variable TERM has been
223 exported, as illustrated on the profile(5) manual page.
224
225 tput -T5620 reset
226 Reset an AT&T 5620 terminal, overriding the type of terminal in
227 the environmental variable TERM.
228
229 tput cup 0 0
230 Send the sequence to move the cursor to row 0, column 0 (the upper
231 left corner of the screen, usually known as the “home” cursor po‐
232 sition).
233
234 tput clear
235 Echo the clear-screen sequence for the current terminal.
236
237 tput cols
238 Print the number of columns for the current terminal.
239
240 tput -T450 cols
241 Print the number of columns for the 450 terminal.
242
243 bold=`tput smso` offbold=`tput rmso`
244 Set the shell variables bold, to begin stand-out mode sequence,
245 and offbold, to end standout mode sequence, for the current termi‐
246 nal. This might be followed by a prompt: echo "${bold}Please type
247 in your name: ${offbold}\c"
248
249 tput hc
250 Set exit code to indicate if the current terminal is a hard copy
251 terminal.
252
253 tput cup 23 4
254 Send the sequence to move the cursor to row 23, column 4.
255
256 tput cup
257 Send the terminfo string for cursor-movement, with no parameters
258 substituted.
259
260 tput longname
261 Print the long name from the terminfo database for the type of
262 terminal specified in the environmental variable TERM.
263
264 tput -S <<!
265 > clear
266 > cup 10 10
267 > bold
268 > !
269
270 This example shows tput processing several capabilities in one in‐
271 vocation. It clears the screen, moves the cursor to position 10,
272 10 and turns on bold (extra bright) mode. The list is terminated
273 by an exclamation mark (!) on a line by itself.
274
276 /usr/share/terminfo
277 compiled terminal description database
278
279 /usr/share/tabset/*
280 tab settings for some terminals, in a format appropriate to be
281 output to the terminal (escape sequences that set margins and
282 tabs); for more information, see the Tabs and Initialization,
283 section of terminfo(5)
284
286 If the -S option is used, tput checks for errors from each line, and if
287 any errors are found, will set the exit code to 4 plus the number of
288 lines with errors. If no errors are found, the exit code is 0. No in‐
289 dication of which line failed can be given so exit code 1 will never
290 appear. Exit codes 2, 3, and 4 retain their usual interpretation. If
291 the -S option is not used, the exit code depends on the type of cap‐
292 name:
293
294 boolean
295 a value of 0 is set for TRUE and 1 for FALSE.
296
297 string a value of 0 is set if the capname is defined for this termi‐
298 nal type (the value of capname is returned on standard out‐
299 put); a value of 1 is set if capname is not defined for this
300 terminal type (nothing is written to standard output).
301
302 integer
303 a value of 0 is always set, whether or not capname is defined
304 for this terminal type. To determine if capname is defined
305 for this terminal type, the user must test the value written
306 to standard output. A value of -1 means that capname is not
307 defined for this terminal type.
308
309 other reset or init may fail to find their respective files. In
310 that case, the exit code is set to 4 + errno.
311
312 Any other exit code indicates an error; see the DIAGNOSTICS section.
313
315 tput prints the following error messages and sets the corresponding
316 exit codes.
317
318 exit code error message
319 ─────────────────────────────────────────────────────────────────────
320 0 (capname is a numeric variable that is not specified in
321 the terminfo(5) database for this terminal type, e.g.
322 tput -T450 lines and tput -Thp2621 xmc)
323 1 no error message is printed, see the EXIT CODES section.
324 2 usage error
325 3 unknown terminal type or no terminfo database
326 4 unknown terminfo capability capname
327 >4 error occurred in -S
328 ─────────────────────────────────────────────────────────────────────
329
331 The tput command was begun by Bill Joy in 1980. The initial version
332 only cleared the screen.
333
334 AT&T System V provided a different tput command:
335
336 • SVr2 provided a rudimentary tput which checked the parameter
337 against each predefined capability and returned the corresponding
338 value. This version of tput did not use tparm(3X) for the capabil‐
339 ities which are parameterized.
340
341 • SVr3 replaced that, a year later, by a more extensive program whose
342 init and reset subcommands (more than half the program) were incor‐
343 porated from the reset feature of BSD tset written by Eric Allman.
344
345 • SVr4 added color initialization using the orig_colors and orig_pair
346 capabilities in the init subcommand.
347
348 Keith Bostic replaced the BSD tput command in 1989 with a new implemen‐
349 tation based on the AT&T System V program tput. Like the AT&T program,
350 Bostic's version accepted some parameters named for terminfo capabili‐
351 ties (clear, init, longname and reset). However (because he had only
352 termcap available), it accepted termcap names for other capabilities.
353 Also, Bostic's BSD tput did not modify the terminal I/O modes as the
354 earlier BSD tset had done.
355
356 At the same time, Bostic added a shell script named “clear”, which used
357 tput to clear the screen.
358
359 Both of these appeared in 4.4BSD, becoming the “modern” BSD implementa‐
360 tion of tput.
361
362 This implementation of tput began from a different source than AT&T or
363 BSD: Ross Ridge's mytinfo package, published on comp.sources.unix in
364 December 1992. Ridge's program made more sophisticated use of the ter‐
365 minal capabilities than the BSD program. Eric Raymond used that tput
366 program (and other parts of mytinfo) in ncurses in June 1995. Using
367 the portions dealing with terminal capabilities almost without change,
368 Raymond made improvements to the way the command-line parameters were
369 handled.
370
372 This implementation of tput differs from AT&T tput in two important ar‐
373 eas:
374
375 • tput capname writes to the standard output. That need not be a
376 regular terminal. However, the subcommands which manipulate termi‐
377 nal modes may not use the standard output.
378
379 The AT&T implementation's init and reset commands use the BSD
380 (4.1c) tset source, which manipulates terminal modes. It succes‐
381 sively tries standard output, standard error, standard input before
382 falling back to “/dev/tty” and finally just assumes a 1200Bd termi‐
383 nal. When updating terminal modes, it ignores errors.
384
385 Until changes made after ncurses 6.0, tput did not modify terminal
386 modes. tput now uses a similar scheme, using functions shared with
387 tset (and ultimately based on the 4.4BSD tset). If it is not able
388 to open a terminal, e.g., when running in cron(1), tput will return
389 an error.
390
391 • AT&T tput guesses the type of its capname operands by seeing if all
392 of the characters are numeric, or not.
393
394 Most implementations which provide support for capname operands use
395 the tparm function to expand parameters in it. That function ex‐
396 pects a mixture of numeric and string parameters, requiring tput to
397 know which type to use.
398
399 This implementation uses a table to determine the parameter types
400 for the standard capname operands, and an internal library function
401 to analyze nonstandard capname operands.
402
403 Besides providing more reliable operation than AT&T's utility, a
404 portability problem is introduced by this analysis: An OpenBSD de‐
405 veloper adapted the internal library function from ncurses to port
406 NetBSD's termcap-based tput to terminfo. That had been modified to
407 interpret multiple commands on a line. Portable applications
408 should not rely upon this feature; ncurses provides it to support
409 applications written specifically for OpenBSD.
410
411 This implementation (unlike others) can accept both termcap and ter‐
412 minfo names for the capname feature, if termcap support is compiled in.
413 However, the predefined termcap and terminfo names have two ambiguities
414 in this case (and the terminfo name is assumed):
415
416 • The termcap name dl corresponds to the terminfo name dl1 (delete
417 one line).
418 The terminfo name dl corresponds to the termcap name DL (delete a
419 given number of lines).
420
421 • The termcap name ed corresponds to the terminfo name rmdc (end
422 delete mode).
423 The terminfo name ed corresponds to the termcap name cd (clear to
424 end of screen).
425
426 The longname and -S options, and the parameter-substitution features
427 used in the cup example, were not supported in BSD curses before
428 4.3reno (1989) or in AT&T/USL curses before SVr4 (1988).
429
430 IEEE Std 1003.1/The Open Group Base Specifications Issue 7
431 (POSIX.1-2008) documents only the operands for clear, init and reset.
432 There are a few interesting observations to make regarding that:
433
434 • In this implementation, clear is part of the capname support. The
435 others (init and longname) do not correspond to terminal capabili‐
436 ties.
437
438 • Other implementations of tput on SVr4-based systems such as So‐
439 laris, IRIX64 and HPUX as well as others such as AIX and Tru64 pro‐
440 vide support for capname operands.
441
442 • A few platforms such as FreeBSD recognize termcap names rather than
443 terminfo capability names in their respective tput commands. Since
444 2010, NetBSD's tput uses terminfo names. Before that, it (like
445 FreeBSD) recognized termcap names.
446
447 Beginning in 2021, FreeBSD uses the ncurses tput, configured for
448 both terminfo (tested first) and termcap (as a fallback).
449
450 Because (apparently) all of the certified Unix systems support the full
451 set of capability names, the reasoning for documenting only a few may
452 not be apparent.
453
454 • X/Open Curses Issue 7 documents tput differently, with capname and
455 the other features used in this implementation.
456
457 • That is, there are two standards for tput: POSIX (a subset) and
458 X/Open Curses (the full implementation). POSIX documents a subset
459 to avoid the complication of including X/Open Curses and the termi‐
460 nal capabilities database.
461
462 • While it is certainly possible to write a tput program without us‐
463 ing curses, none of the systems which have a curses implementation
464 provide a tput utility which does not provide the capname feature.
465
466 X/Open Curses Issue 7 (2009) is the first version to document utili‐
467 ties. However that part of X/Open Curses does not follow existing
468 practice (i.e., Unix features documented in SVID 3):
469
470 • It assigns exit code 4 to “invalid operand”, which may be the same
471 as unknown capability. For instance, the source code for Solaris'
472 xcurses uses the term “invalid” in this case.
473
474 • It assigns exit code 255 to a numeric variable that is not speci‐
475 fied in the terminfo database. That likely is a documentation er‐
476 ror, confusing the -1 written to the standard output for an absent
477 or cancelled numeric value versus an (unsigned) exit code.
478
479 The various Unix systems (AIX, HPUX, Solaris) use the same exit-codes
480 as ncurses.
481
482 NetBSD curses documents different exit codes which do not correspond to
483 either ncurses or X/Open.
484
486 clear(1), stty(1), tabs(1), tset(1), curs_termcap(3X), terminfo(5).
487
488 This describes ncurses version 6.4 (patch 20230520).
489
490
491
492 tput(1)