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
44 capabilities must be passed to tput from the standard input
45 instead of from the command line (see example). Only one cap‐
46 name is allowed per line. The -S option changes the meaning of
47 the 0 and 1 boolean and string exit codes (see the EXIT CODES
48 section).
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
70 reset 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
102 updating 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 columns. tput calls
201 setupterm(3X) 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
216 finally, 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
232 position).
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
271 invocation. It clears the screen, moves the cursor to position
272 10, 10 and turns on bold (extra bright) mode. The list is termi‐
273 nated 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
289 indication 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 -T2621 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, whose init and reset
335 subcommands (more than half the program) were incorporated from the
336 reset feature of BSD tset written by Eric Allman.
337
338 Keith Bostic replaced the BSD tput command in 1989 with a new implemen‐
339 tation based on the AT&T System V program tput. Like the AT&T program,
340 Bostic's version accepted some parameters named for terminfo capabili‐
341 ties (clear, init, longname and reset). However (because he had only
342 termcap available), it accepted termcap names for other capabilities.
343 Also, Bostic's BSD tput did not modify the terminal I/O modes as the
344 earlier BSD tset had done.
345
346 At the same time, Bostic added a shell script named “clear”, which used
347 tput to clear the screen.
348
349 Both of these appeared in 4.4BSD, becoming the “modern” BSD implementa‐
350 tion of tput.
351
352 This implementation of tput began from a different source than AT&T or
353 BSD: Ross Ridge's mytinfo package, published on comp.sources.unix in
354 December 1992. Ridge's program made more sophisticated use of the ter‐
355 minal capabilities than the BSD program. Eric Raymond used that tput
356 program (and other parts of mytinfo) in ncurses in June 1995. Using
357 the portions dealing with terminal capabilities almost without change,
358 Raymond made improvements to the way the command-line parameters were
359 handled.
360
362 This implementation of tput differs from AT&T tput in two important
363 areas:
364
365 · tput capname writes to the standard output. That need not be a
366 regular terminal. However, the subcommands which manipulate termi‐
367 nal modes may not use the standard output.
368
369 The AT&T implementation's init and reset commands use the BSD
370 (4.1c) tset source, which manipulates terminal modes. It succes‐
371 sively tries standard output, standard error, standard input before
372 falling back to “/dev/tty” and finally just assumes a 1200Bd termi‐
373 nal. When updating terminal modes, it ignores errors.
374
375 Until changes made after ncurses 6.0, tput did not modify terminal
376 modes. tput now uses a similar scheme, using functions shared with
377 tset (and ultimately based on the 4.4BSD tset). If it is not able
378 to open a terminal, e.g., when running in cron, tput will return an
379 error.
380
381 · AT&T tput guesses the type of its capname operands by seeing if all
382 of the characters are numeric, or not.
383
384 Most implementations which provide support for capname operands use
385 the tparm function to expand parameters in it. That function
386 expects a mixture of numeric and string parameters, requiring tput
387 to know which type to use.
388
389 This implementation uses a table to determine the parameter types
390 for the standard capname operands, and an internal library function
391 to analyze nonstandard capname operands.
392
393 This implementation (unlike others) can accept both termcap and ter‐
394 minfo names for the capname feature, if termcap support is compiled in.
395 However, the predefined termcap and terminfo names have two ambiguities
396 in this case (and the terminfo name is assumed):
397
398 · The termcap name dl corresponds to the terminfo name dl1 (delete
399 one line).
400 The terminfo name dl corresponds to the termcap name DL (delete a
401 given number of lines).
402
403 · The termcap name ed corresponds to the terminfo name rmdc (end
404 delete mode).
405 The terminfo name ed corresponds to the termcap name cd (clear to
406 end of screen).
407
408 The longname and -S options, and the parameter-substitution features
409 used in the cup example, were not supported in BSD curses before
410 4.3reno (1989) or in AT&T/USL curses before SVr4 (1988).
411
412 IEEE Std 1003.1/The Open Group Base Specifications Issue 7
413 (POSIX.1-2008) documents only the operands for clear, init and reset.
414 There are a few interesting observations to make regarding that:
415
416 · In this implementation, clear is part of the capname support. The
417 others (init and longname) do not correspond to terminal capabili‐
418 ties.
419
420 · Other implementations of tput on SVr4-based systems such as
421 Solaris, IRIX64 and HPUX as well as others such as AIX and Tru64
422 provide support for capname operands.
423
424 · A few platforms such as FreeBSD recognize termcap names rather than
425 terminfo capability names in their respective tput commands. Since
426 2010, NetBSD's tput uses terminfo names. Before that, it (like
427 FreeBSD) recognized termcap names.
428
429 Because (apparently) all of the certified Unix systems support the full
430 set of capability names, the reasoning for documenting only a few may
431 not be apparent.
432
433 · X/Open Curses Issue 7 documents tput differently, with capname and
434 the other features used in this implementation.
435
436 · That is, there are two standards for tput: POSIX (a subset) and
437 X/Open Curses (the full implementation). POSIX documents a subset
438 to avoid the complication of including X/Open Curses and the termi‐
439 nal capabilities database.
440
441 · While it is certainly possible to write a tput program without
442 using curses, none of the systems which have a curses implementa‐
443 tion provide a tput utility which does not provide the capname fea‐
444 ture.
445
446 X/Open Curses Issue 7 (2009) is the first version to document utili‐
447 ties. However that part of X/Open Curses does not follow existing
448 practice (i.e., Unix features documented in SVID 3):
449
450 · It assigns exit code 4 to “invalid operand”, which may be the same
451 as unknown capability. For instance, the source code for Solaris'
452 xcurses uses the term “invalid” in this case.
453
454 · It assigns exit code 255 to a numeric variable that is not speci‐
455 fied in the terminfo database. That likely is a documentation
456 error, confusing the -1 written to the standard output for an
457 absent or cancelled numeric value versus an (unsigned) exit code.
458
459 The various Unix systems (AIX, HPUX, Solaris) use the same exit-codes
460 as ncurses.
461
462 NetBSD curses documents different exit codes which do not correspond to
463 either ncurses or X/Open.
464
466 clear(1), stty(1), tabs(1), tset(1), terminfo(5), curs_termcap(3X).
467
468 This describes ncurses version 6.1 (patch 20191109).
469
470
471
472 tput(1)