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