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