]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/tput.1
10e47b7b32161fd469994ff62fa590b542a9d23e
[ncurses.git] / man / tput.1
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2017,2018 Free Software Foundation, Inc.              *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: tput.1,v 1.58 2018/05/19 21:07:46 tom Exp $
31 .TH @TPUT@ 1 ""
32 .ds d @TERMINFO@
33 .ds n 1
34 .ie \n(.g .ds `` \(lq
35 .el       .ds `` ``
36 .ie \n(.g .ds '' \(rq
37 .el       .ds '' ''
38 .de bP
39 .ie n  .IP \(bu 4
40 .el    .IP \(bu 2
41 ..
42 .SH NAME
43 \fB@TPUT@\fR, \fBreset\fR \- initialize a terminal or query terminfo database
44 .SH SYNOPSIS
45 \fB@TPUT@\fR [\fB\-T\fR\fItype\fR] \fIcapname\fR [\fIparameters\fR]
46 .br
47 \fB@TPUT@\fR [\fB\-T\fR\fItype\fR] [\fB\-x\fP] \fBclear\fR
48 .br
49 \fB@TPUT@\fR [\fB\-T\fR\fItype\fR] \fBinit\fR
50 .br
51 \fB@TPUT@\fR [\fB\-T\fR\fItype\fR] \fBreset\fR
52 .br
53 \fB@TPUT@\fR [\fB\-T\fR\fItype\fR] \fBlongname\fR
54 .br
55 \fB@TPUT@ \-S\fR  \fB<<\fR
56 .br
57 \fB@TPUT@ \-V\fR
58 .br
59 .SH DESCRIPTION
60 The \fB@TPUT@\fR utility uses the \fBterminfo\fR database to make the
61 values of terminal-dependent capabilities and information available to
62 the shell (see \fBsh\fR(1)), to initialize or reset the terminal, or
63 return the long name of the requested terminal type.
64 The result depends upon the capability's type:
65 .RS 3
66 .TP 5
67 string
68 \fB@TPUT@\fR writes the string to the standard output.
69 No trailing newline is supplied.
70 .TP
71 integer
72 \fB@TPUT@\fR writes the decimal value to the standard output,
73 with a trailing newline.
74 .TP
75 boolean
76 \fB@TPUT@\fR simply sets the exit code
77 (\fB0\fR for TRUE if the terminal has the capability,
78 \fB1\fR for FALSE if it does not),
79 and writes nothing to the standard output.
80 .RE
81 .PP
82 Before using a value returned on the standard output,
83 the application should test the exit code
84 (e.g., \fB$?\fR, see \fBsh\fR(1)) to be sure it is \fB0\fR.
85 (See the \fBEXIT CODES\fR and \fBDIAGNOSTICS\fR sections.)
86 For a complete list of capabilities
87 and the \fIcapname\fR associated with each, see \fBterminfo\fR(5).
88 .SS Options
89 .TP
90 \fB\-S\fR
91 allows more than one capability per invocation of \fB@TPUT@\fR.  The
92 capabilities must be passed to \fB@TPUT@\fR from the standard input
93 instead of from the command line (see example).
94 Only one \fIcapname\fR is allowed per line.
95 The \fB\-S\fR option changes the
96 meaning of the \fB0\fR and \fB1\fR boolean and string exit codes (see the
97 EXIT CODES section).
98 .IP
99 Because some capabilities may use
100 \fIstring\fP parameters rather than \fInumbers\fP,
101 \fB@TPUT@\fR uses a table and the presence of parameters in its input
102 to decide whether to use \fBtparm\fR(3X),
103 and how to interpret the parameters.
104 .TP
105 \fB\-T\fR\fItype\fR
106 indicates the \fItype\fR of terminal.
107 Normally this option is
108 unnecessary, because the default is taken from the environment
109 variable \fBTERM\fR.
110 If \fB\-T\fR is specified, then the shell
111 variables \fBLINES\fR and \fBCOLUMNS\fR will also be ignored.
112 .TP
113 \fB\-V\fR
114 reports the version of ncurses which was used in this program, and exits.
115 .TP
116 .B \-x
117 do not attempt to clear the terminal's scrollback buffer
118 using the extended \*(``E3\*('' capability.
119 .SS Commands
120 A few commands (\fBinit\fP, \fBreset\fP and \fBlongname\fP) are
121 special; they are defined by the \fB@TPUT@\fP program.
122 The others are the names of \fIcapabilities\fP from the terminal database
123 (see \fBterminfo\fR(5) for a list).
124 Although \fBinit\fP and \fBreset\fP resemble capability names,
125 \fB@TPUT@\fP uses several capabilities to perform these special functions.
126 .TP
127 \fIcapname\fR
128 indicates the capability from the terminal database.
129 .IP
130 If the capability is a string that takes parameters, the arguments
131 following the capability will be used as parameters for the string.
132 .IP
133 Most parameters are numbers.
134 Only a few terminal capabilities require string parameters;
135 \fB@TPUT@\fR uses a table to decide which to pass as strings.
136 Normally \fB@TPUT@\fR uses \fBtparm\fR(3X) to perform the substitution.
137 If no parameters are given for the capability,
138 \fB@TPUT@\fR writes the string without performing the substitution.
139 .TP
140 \fBinit\fR
141 If the terminal database is present and an entry for the user's
142 terminal exists (see \fB\-T\fR\fItype\fR, above), the following will
143 occur:
144 .RS
145 .TP 5
146 (1)
147 first, \fB@TPUT@\fR retrieves the current terminal mode settings
148 for your terminal.
149 It does this by successively testing
150 .RS
151 .bP
152 the standard error,
153 .bP
154 standard output,
155 .bP
156 standard input and
157 .bP
158 ultimately \*(``/dev/tty\*(''
159 .RE
160 .IP
161 to obtain terminal settings.
162 Having retrieved these settings, \fB@TPUT@\fP remembers which
163 file descriptor to use when updating settings.
164 .TP
165 (2)
166 if the window size cannot be obtained from the operating system,
167 but the terminal description (or environment, e.g., \fBLINES\fP
168 and \fBCOLUMNS\fP variables specify this),
169 update the operating system's notion of the window size.
170 .TP
171 (3)
172 the terminal modes will be updated:
173 .RS
174 .bP
175 any delays (e.g., newline) specified in the entry will
176 be set in the tty driver,
177 .bP
178 tabs expansion will be turned on or off according to
179 the specification in the entry, and
180 .bP
181 if tabs are not expanded,
182 standard tabs will be set (every 8 spaces).
183 .RE
184 .TP
185 (4)
186 if present, the terminal's initialization strings will be
187 output as detailed in the \fBterminfo\fR(5) section on
188 .IR "Tabs and Initialization" ,
189 .TP
190 (5)
191 output is flushed.
192 .RE
193 .IP
194 If an entry does not
195 contain the information needed for any of these activities,
196 that activity will silently be skipped.
197 .TP
198 \fBreset\fR
199 This is similar to \fBinit\fP, with two differences:
200 .RS
201 .TP 5
202 (1)
203 before any other initialization,
204 the terminal modes will be reset to a \*(``sane\*('' state:
205 .RS
206 .bP
207 set cooked and echo modes,
208 .bP
209 turn off cbreak and raw modes,
210 .bP
211 turn on newline translation and
212 .bP
213 reset any unset special characters to their default values
214 .RE
215 .TP 5
216 (2)
217 Instead of putting out \fIinitialization\fP strings, the terminal's
218 \fIreset\fP strings will be output if present
219 (\fBrs1\fR, \fBrs2\fR, \fBrs3\fR, \fBrf\fR).
220 If the \fIreset\fP strings are not present, but \fIinitialization\fP
221 strings are, the \fIinitialization\fP strings will be output.
222 .RE
223 .IP
224 Otherwise, \fBreset\fR acts identically to \fBinit\fR.
225 .TP
226 \fBlongname\fR
227 If the terminal database is present and an entry for the
228 user's terminal exists (see \fB\-T\fR\fItype\fR above), then the long name
229 of the terminal will be put out.  The long name is the last
230 name in the first line of the terminal's description in the
231 \fBterminfo\fR database [see \fBterm\fR(5)].
232 .SS Aliases
233 \fB@TPUT@\fR handles the \fBclear\fP, \fBinit\fP and \fBreset\fP
234 commands specially:
235 it allows for the possibility that it is invoked by a link with those names.
236 .PP
237 If \fB@TPUT@\fR is invoked by a link named \fBreset\fR, this has the
238 same effect as \fB@TPUT@ reset\fR.
239 The \fB@TSET@\fR(\*n) utility also treats a link named \fBreset\fP specially.
240 .PP
241 Before ncurses 6.1, the two utilities were different from each other:
242 .bP
243 \fB@TSET@\fP utility reset the terminal modes and special characters
244 (not done with \fB@TPUT@\fP).
245 .bP
246 On the other hand, \fB@TSET@\fP's repertoire of terminal capabilities for
247 resetting the terminal was more limited,
248 i.e., only \fBreset_1string\fP, \fBreset_2string\fP and \fBreset_file\fP
249 in contrast to the tab-stops and margins which are set by this utility.
250 .bP
251 The \fBreset\fP program is usually an alias for \fB@TSET@\fP,
252 because of this difference with resetting terminal modes and special characters.
253 .PP
254 With the changes made for ncurses 6.1, the \fIreset\fP feature of the
255 two programs is (mostly) the same.  A few differences remain:
256 .bP
257 The \fB@TSET@\fP program waits one second when resetting,
258 in case it happens to be a hardware terminal.
259 .bP
260 The two programs write the terminal initialization strings
261 to different streams (i.e.,. the standard error for \fB@TSET@\fP and the
262 standard output for \fB@TPUT@\fP).
263 .IP
264 \fBNote:\fP although these programs write to different streams,
265 redirecting their output to a file will capture only part of their actions.
266 The changes to the terminal modes are not affected by redirecting the output.
267 .PP
268 If \fB@TPUT@\fR is invoked by a link named \fBinit\fR, this has the
269 same effect as \fB@TPUT@ init\fR.
270 Again, you are less likely to use that link because another program
271 named \fBinit\fP has a more well-established use.
272 .SH EXAMPLES
273 .TP 5
274 \fB@TPUT@ init\fR
275 Initialize the terminal according to the type of
276 terminal in the environmental variable \fBTERM\fR.  This
277 command should be included in everyone's .profile after
278 the environmental variable \fBTERM\fR has been exported, as
279 illustrated on the \fBprofile\fR(5) manual page.
280 .TP 5
281 \fB@TPUT@ \-T5620 reset\fR
282 Reset an AT&T 5620 terminal, overriding the type of
283 terminal in the environmental variable \fBTERM\fR.
284 .TP 5
285 \fB@TPUT@ cup 0 0\fR
286 Send the sequence to move the cursor to row \fB0\fR, column \fB0\fR
287 (the upper left corner of the screen, usually known as the \*(``home\*(''
288 cursor position).
289 .TP 5
290 \fB@TPUT@ clear\fR
291 Echo the clear-screen sequence for the current terminal.
292 .TP 5
293 \fB@TPUT@ cols\fR
294 Print the number of columns for the current terminal.
295 .TP 5
296 \fB@TPUT@ \-T450 cols\fR
297 Print the number of columns for the 450 terminal.
298 .TP 5
299 \fBbold=`@TPUT@ smso` offbold=`@TPUT@ rmso`\fR
300 Set the shell variables \fBbold\fR, to begin stand-out mode
301 sequence, and \fBoffbold\fR, to end standout mode sequence,
302 for the current terminal.  This might be followed by a
303 prompt: \fBecho "${bold}Please type in your name: ${offbold}\\c"\fR
304 .TP 5
305 \fB@TPUT@ hc\fR
306 Set exit code to indicate if the current terminal is a hard copy terminal.
307 .TP 5
308 \fB@TPUT@ cup 23 4\fR
309 Send the sequence to move the cursor to row 23, column 4.
310 .TP 5
311 \fB@TPUT@ cup\fR
312 Send the terminfo string for cursor-movement, with no parameters substituted.
313 .TP 5
314 \fB@TPUT@ longname\fR
315 Print the long name from the \fBterminfo\fR database for the
316 type of terminal specified in the environmental
317 variable \fBTERM\fR.
318 .PP
319 .RS 5
320 \fB@TPUT@ \-S <<!\fR
321 .br
322 \fB> clear\fR
323 .br
324 \fB> cup 10 10\fR
325 .br
326 \fB> bold\fR
327 .br
328 \fB> !\fR
329 .RE
330 .TP 5
331 \&
332 This example shows \fB@TPUT@\fR processing several capabilities
333 in one invocation.
334 It clears the screen,
335 moves the cursor to position 10, 10
336 and turns on bold (extra bright) mode.
337 The list is terminated by an exclamation mark (\fB!\fR) on a line by itself.
338 .SH FILES
339 .TP
340 \fB\*d\fR
341 compiled terminal description database
342 .TP
343 \fB@DATADIR@/tabset/*\fR
344 tab settings for some terminals, in a format
345 appropriate to be output to the terminal (escape
346 sequences that set margins and tabs); for more
347 information, see the
348 .IR "Tabs and Initialization" ,
349 section of \fBterminfo\fR(5)
350 .SH EXIT CODES
351 If the \fB\-S\fR option is used,
352 \fB@TPUT@\fR checks for errors from each line,
353 and if any errors are found, will set the exit code to 4 plus the
354 number of lines with errors.
355 If no errors are found, the exit code is \fB0\fR.
356 No indication of which line failed can be given so
357 exit code \fB1\fR will never appear.  Exit codes \fB2\fR, \fB3\fR, and
358 \fB4\fR retain their usual interpretation.
359 If the \fB\-S\fR option is not used,
360 the exit code depends on the type of \fIcapname\fR:
361 .RS 3
362 .TP
363 .I boolean
364 a value of \fB0\fR is set for TRUE and \fB1\fR for FALSE.
365 .TP
366 .I string
367 a value of \fB0\fR is set if the
368 \fIcapname\fR is defined for this terminal \fItype\fR (the value of
369 \fIcapname\fR is returned on standard output);
370 a value of \fB1\fR is set if \fIcapname\fR
371 is not defined for this terminal \fItype\fR
372 (nothing is written to standard output).
373 .TP
374 .I integer
375 a value of \fB0\fR is always set,
376 whether or not \fIcapname\fR is defined for this terminal \fItype\fR.
377 To determine if \fIcapname\fR is defined for this terminal \fItype\fR,
378 the user must test the value written to standard output.
379 A value of \fB\-1\fR
380 means that \fIcapname\fR is not defined for this terminal \fItype\fR.
381 .TP
382 .I other
383 \fBreset\fR or \fBinit\fR may fail to find their respective files.
384 In that case, the exit code is set to 4 + \fBerrno\fR.
385 .RE
386 .PP
387 Any other exit code indicates an error; see the DIAGNOSTICS section.
388 .SH DIAGNOSTICS
389 \fB@TPUT@\fR prints the following error messages and sets the corresponding exit
390 codes.
391 .PP
392 .ne 15
393 .TS
394 l l.
395 exit code       error message
396 =
397 \fB0\fR T{
398 (\fIcapname\fR is a numeric variable that is not specified in the
399 \fBterminfo\fR(5) database for this terminal type, e.g.
400 \fB@TPUT@ \-T450 lines\fR and \fB@TPUT@ \-T2621 xmc\fR)
401 T}
402 \fB1\fR no error message is printed, see the \fBEXIT CODES\fR section.
403 \fB2\fR usage error
404 \fB3\fR unknown terminal \fItype\fR or no \fBterminfo\fR database
405 \fB4\fR unknown \fBterminfo\fR capability \fIcapname\fR
406 \fB>4\fR        error occurred in \-S
407 =
408 .TE
409 .SH HISTORY
410 The \fBtput\fP command was begun by Bill Joy in 1980.
411 The initial version only cleared the screen.
412 .PP
413 AT&T System V provided a different \fBtput\fP command,
414 whose \fBinit\fP and \fBreset\fP  subcommands
415 (more than half the program) were incorporated from
416 the \fBreset\fP feature of BSD \fBtset\fP written by Eric Allman.
417 .PP
418 Keith Bostic replaced the BSD \fBtput\fP command in 1989
419 with a new implementation
420 based on the AT&T System V program \fBtput\fP.
421 Like the AT&T program, Bostic's version
422 accepted some parameters named for \fIterminfo capabilities\fP
423 (\fBclear\fP, \fBinit\fP, \fBlongname\fP and \fBreset\fP).
424 However (because he had only termcap available),
425 it accepted \fItermcap names\fP for other capabilities.
426 Also, Bostic's BSD \fBtput\fP did not modify the terminal I/O modes
427 as the earlier BSD \fBtset\fP had done.
428 .PP
429 At the same time, Bostic added a shell script named \*(``clear\*('',
430 which used \fBtput\fP to clear the screen.
431 .PP
432 Both of these appeared in 4.4BSD,
433 becoming the \*(``modern\*('' BSD implementation of \fBtput\fP.
434 .PP
435 This implementation of \fBtput\fP began from a different source than
436 AT&T or BSD: Ross Ridge's \fImytinfo\fP package, published on
437 \fIcomp.sources.unix\fP in December 1992.
438 Ridge's program made more sophisticated use of the terminal capabilities
439 than the BSD program.
440 Eric Raymond used the \fBtput\fP program
441 (and other parts of \fImytinfo\fP) in ncurses in June 1995.
442 Using the portions dealing with terminal capabilities
443 almost without change,
444 Raymond made improvements to the way the command-line parameters
445 were handled.
446 .SH PORTABILITY
447 .PP
448 This implementation of \fBtput\fP differs from AT&T \fBtput\fP in
449 two important areas:
450 .bP
451 \fB@TPUT@\fP \fIcapname\fP writes to the standard output.
452 That need not be a regular terminal.
453 However, the subcommands which manipulate terminal modes
454 may not use the standard output.
455 .IP
456 The AT&T implementation's \fBinit\fP and \fBreset\fP commands
457 use the BSD (4.1c) \fBtset\fP source, which manipulates terminal modes.
458 It successively tries standard output, standard error, standard input
459 before falling back to \*(``/dev/tty\*('' and finally just assumes
460 a 1200Bd terminal.
461 When updating terminal modes, it ignores errors.
462 .IP
463 Until changes made after ncurses 6.0,
464 \fB@TPUT@\fP did not modify terminal modes.
465 \fB@TPUT@\fP now uses a similar scheme,
466 using functions shared with \fB@TSET@\fP
467 (and ultimately based on the 4.4BSD \fBtset\fP).
468 If it is not able to open a terminal, e.g., when running in \fBcron\fP,
469 \fB@TPUT@\fP will return an error.
470 .bP
471 AT&T \fBtput\fP guesses the type of its \fIcapname\fP operands by seeing if
472 all of the characters are numeric, or not.
473 .IP
474 Most implementations which provide support for \fIcapname\fR operands
475 use the \fItparm\fP function to expand parameters in it.
476 That function expects a mixture of numeric and string parameters,
477 requiring \fB@TPUT@\fP to know which type to use.
478 .IP
479 This implementation uses a table to determine the parameter types for
480 the standard \fIcapname\fR operands, and an internal library
481 function to analyze nonstandard \fIcapname\fR operands.
482 .PP
483 This implementation (unlike others) can accept both \fItermcap\fP
484 and \fIterminfo\fP names for the \fIcapname\fP feature,
485 if
486 \fItermcap\fR support is compiled in.
487 However, the predefined \fItermcap\fP and \fIterminfo\fP names have two
488 ambiguities in this case (and the \fIterminfo\fP name is assumed):
489 .bP
490 The \fItermcap\fP name \fBdl\fP corresponds to
491 the \fIterminfo\fP name \fBdl1\fP (delete one line).
492 .br
493 The \fIterminfo\fP name \fBdl\fP corresponds to
494 the \fItermcap\fP name \fBDL\fP (delete a given number of lines).
495 .bP
496 The \fItermcap\fP name \fBed\fP corresponds to
497 the \fIterminfo\fP name \fBrmdc\fP (end delete mode).
498 .br
499 The \fIterminfo\fP name \fBed\fP corresponds to
500 the \fItermcap\fP name \fBcd\fP (clear to end of screen).
501 .PP
502 The \fBlongname\fR and \fB\-S\fR options, and the parameter-substitution
503 features used in the \fBcup\fR example,
504 were not supported in BSD curses before 4.3reno (1989) or in
505 AT&T/USL curses before SVr4 (1988).
506 .PP
507 IEEE Std 1003.1/The Open Group  Base Specifications Issue 7 (POSIX.1-2008) 
508 documents only the operands for \fBclear\fP, \fBinit\fP and \fBreset\fP.
509 There are a few interesting observations to make regarding that:
510 .bP
511 In this implementation, \fBclear\fP is part of the \fIcapname\fR support.
512 The others (\fBinit\fP and \fBlongname\fP) do not correspond to terminal
513 capabilities.
514 .bP
515 Other implementations of \fBtput\fP on
516 SVr4-based systems such as Solaris, IRIX64 and HPUX
517 as well as others such as AIX and Tru64
518 provide support for \fIcapname\fR operands.
519 .bP
520 A few platforms such as FreeBSD recognize termcap names rather
521 than terminfo capability names in their respective \fBtput\fP commands.
522 Since 2010, NetBSD's \fBtput\fP uses terminfo names.
523 Before that, it (like FreeBSD) recognized termcap names.
524 .PP
525 Because (apparently) \fIall\fP of the certified Unix systems
526 support the full set of capability names, the reasoning for documenting
527 only a few may not be apparent.
528 .bP
529 X/Open Curses Issue 7 documents \fBtput\fP differently, with \fIcapname\fP
530 and the other features used in this implementation.
531 .bP
532 That is, there are two standards for \fBtput\fP:
533 POSIX (a subset) and X/Open Curses (the full implementation).
534 POSIX documents a subset to avoid the complication of including X/Open Curses
535 and the terminal capabilities database.
536 .bP
537 While it is certainly possible to write a \fBtput\fP program
538 without using curses,
539 none of the systems which have a curses implementation provide
540 a \fBtput\fP utility which does not provide the \fIcapname\fP feature.
541 .SH SEE ALSO
542 \fB@CLEAR@\fR(\*n),
543 \fBstty\fR(1),
544 \fB@TABS@\fR(\*n),
545 \fB@TSET@\fR(\*n),
546 \fBterminfo\fR(5),
547 \fBcurs_termcap\fR(3X).
548 .PP
549 This describes \fBncurses\fR
550 version @NCURSES_MAJOR@.@NCURSES_MINOR@ (patch @NCURSES_PATCH@).