]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_terminfo.3x
ncurses 6.1 - patch 20180303
[ncurses.git] / man / curs_terminfo.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1999-2016,2017 Free Software Foundation, Inc.              *
3 .\"                                                                          *
4 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
5 .\" copy of this software and associated documentation files (the            *
6 .\" "Software"), to deal in the Software without restriction, including      *
7 .\" without limitation the rights to use, copy, modify, merge, publish,      *
8 .\" distribute, distribute with modifications, sublicense, and/or sell       *
9 .\" copies of the Software, and to permit persons to whom the Software is    *
10 .\" furnished to do so, subject to the following conditions:                 *
11 .\"                                                                          *
12 .\" The above copyright notice and this permission notice shall be included  *
13 .\" in all copies or substantial portions of the Software.                   *
14 .\"                                                                          *
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 .\"                                                                          *
23 .\" Except as contained in this notice, the name(s) of the above copyright   *
24 .\" holders shall not be used in advertising or otherwise to promote the     *
25 .\" sale, use or other dealings in this Software without prior written       *
26 .\" authorization.                                                           *
27 .\"***************************************************************************
28 .\"
29 .\" $Id: curs_terminfo.3x,v 1.57 2017/11/21 00:46:31 tom Exp $
30 .TH curs_terminfo 3X ""
31 .ie \n(.g .ds `` \(lq
32 .el       .ds `` ``
33 .ie \n(.g .ds '' \(rq
34 .el       .ds '' ''
35 .de bP
36 .ie n  .IP \(bu 4
37 .el    .IP \(bu 2
38 ..
39 .ds n 5
40 .na
41 .hy 0
42 .SH NAME
43 \fBdel_curterm\fR,
44 \fBmvcur\fR,
45 \fBputp\fR,
46 \fBrestartterm\fR,
47 \fBset_curterm\fR,
48 \fBsetterm\fR,
49 \fBsetupterm\fR,
50 \fBtigetflag\fR,
51 \fBtigetnum\fR,
52 \fBtigetstr\fR,
53 \fBtiparm\fR,
54 \fBtparm\fR,
55 \fBtputs\fR,
56 \fBvid_attr\fR,
57 \fBvid_puts\fR,
58 \fBvidattr\fR,
59 \fBvidputs\fR \- \fBcurses\fR interfaces to terminfo database
60 .ad
61 .hy
62 .SH SYNOPSIS
63 .nf
64 \fB#include <curses.h>\fR
65 .br
66 \fB#include <term.h>\fR
67 .sp
68 \fBTERMINAL *cur_term;\fR
69 .sp
70 \fBconst char * const boolnames[];\fP
71 \fBconst char * const boolcodes[];\fP
72 \fBconst char * const boolfnames[];\fP
73 \fBconst char * const numnames[];\fP
74 \fBconst char * const numcodes[];\fP
75 \fBconst char * const numfnames[];\fP
76 \fBconst char * const strnames[];\fP
77 \fBconst char * const strcodes[];\fP
78 \fBconst char * const strfnames[];\fP
79 .sp
80 \fBint setupterm(const char *\fR\fIterm\fR\fB, int \fR\fIfiledes\fR\fB, int *\fR\fIerrret\fR\fB);\fR
81 .br
82 \fBint setterm(const char *\fR\fIterm\fR\fB);\fR
83 .br
84 \fBTERMINAL *set_curterm(TERMINAL *\fR\fInterm\fR\fB);\fR
85 .br
86 \fBint del_curterm(TERMINAL *\fR\fIoterm\fR\fB);\fR
87 .br
88 \fBint restartterm(const char *\fR\fIterm\fR\fB, int \fR\fIfiledes\fR\fB, int *\fR\fIerrret\fR\fB);\fR
89 .sp
90 \fBchar *tparm(const char *\fR\fIstr\fR\fB, ...);\fR
91 .br
92 \fBint tputs(const char *\fR\fIstr\fR\fB, int \fR\fIaffcnt\fR\fB, int (*\fR\fIputc\fR\fB)(int));\fR
93 .br
94 \fBint putp(const char *\fR\fIstr\fR\fB);\fR
95 .sp
96 \fBint vidputs(chtype \fR\fIattrs\fR\fB, int (*\fR\fIputc\fR\fB)(int));\fR
97 .br
98 \fBint vidattr(chtype \fR\fIattrs\fR\fB);\fR
99 .br
100 \fBint vid_puts(attr_t \fR\fIattrs\fR\fB, short \fR\fIpair\fR\fB, void *\fR\fIopts\fR\fB, int (*\fR\fIputc\fR\fB)(int));\fR
101 .br
102 \fBint vid_attr(attr_t \fR\fIattrs\fR\fB, short \fR\fIpair\fR\fB, void *\fR\fIopts\fR\fB);\fR
103 .sp
104 \fBint mvcur(int \fR\fIoldrow\fR\fB, int \fR\fIoldcol\fR\fB, int \fR\fInewrow\fR, int \fR\fInewcol\fR\fB);\fR
105 .sp
106 \fBint tigetflag(const char *\fR\fIcapname\fR\fB);\fR
107 .br
108 \fBint tigetnum(const char *\fR\fIcapname\fR\fB);\fR
109 .br
110 \fBchar *tigetstr(const char *\fR\fIcapname\fR\fB);\fR
111 .sp
112 \fBchar *tiparm(const char *\fR\fIstr\fR\fB, ...);\fR
113 .br
114 .fi
115 .SH DESCRIPTION
116 These low-level routines must be called by programs that have to deal
117 directly with the \fBterminfo\fR database to handle certain terminal
118 capabilities, such as programming function keys.  For all other
119 functionality, \fBcurses\fR routines are more suitable and their use is
120 recommended.
121 .SS Initialization
122 .PP
123 Initially, \fBsetupterm\fR should be called.
124 The high-level curses functions \fBinitscr\fR and
125 \fBnewterm\fR call \fBsetupterm\fP to initialize the
126 low-level set of terminal-dependent variables
127 [listed in \fBterminfo\fR(\*n)].
128 .PP
129 Applications can use the
130 terminal capabilities either directly (via header definitions),
131 or by special functions.
132 The header files \fBcurses.h\fR and \fBterm.h\fR should be included (in this
133 order) to get the definitions for these strings, numbers, and flags.
134 .PP
135 The \fBterminfo\fR variables
136 \fBlines\fR and \fBcolumns\fR are initialized by \fBsetupterm\fR as
137 follows:
138 .bP
139 If \fBuse_env(FALSE)\fR has been called, values for
140 \fBlines\fR and \fBcolumns\fR specified in \fBterminfo\fR are used.
141 .bP
142 Otherwise, if the environment variables \fBLINES\fR and \fBCOLUMNS\fR
143 exist, their values are used.  If these environment variables do not
144 exist and the program is running in a window, the current window size
145 is used.  Otherwise, if the environment variables do not exist, the
146 values for \fBlines\fR and \fBcolumns\fR specified in the
147 \fBterminfo\fR database are used.
148 .PP
149 Parameterized strings should be passed through \fBtparm\fR to instantiate them. 
150 All \fBterminfo\fR strings [including the output of \fBtparm\fR] should be printed
151 with \fBtputs\fR or \fBputp\fR.
152 Call \fBreset_shell_mode\fR to restore the
153 tty modes before exiting [see \fBcurs_kernel\fR(3X)].
154 .PP
155 Programs which use
156 cursor addressing should
157 .bP
158 output \fBenter_ca_mode\fR upon startup and
159 .bP
160 output \fBexit_ca_mode\fR before exiting.
161 .PP
162 Programs which execute shell subprocesses should
163 .bP
164 call \fBreset_shell_mode\fR and
165 output \fBexit_ca_mode\fR before the shell
166 is called and
167 .bP
168 output \fBenter_ca_mode\fR and
169 call \fBreset_prog_mode\fR after returning from the shell.
170 .PP
171 The \fBsetupterm\fR routine reads in the \fBterminfo\fR database,
172 initializing the \fBterminfo\fR structures, but does not set up the
173 output virtualization structures used by \fBcurses\fR.
174 These are its parameters:
175 .RS 3
176 .TP 5
177 \fIterm\fP
178 is the terminal type, a character string.
179 If \fIterm\fR is null, the environment variable \fBTERM\fR is used.
180 .TP 5
181 \fIfiledes\fP
182 is the file descriptor used for all output.
183 .TP 5
184 \fIerrret\fP
185 points to an optional location where an error status can be returned to
186 the caller.
187 If \fIerrret\fR is not null,
188 then \fBsetupterm\fR returns \fBOK\fR or
189 \fBERR\fR and stores a status value in the integer pointed to by
190 \fIerrret\fR.
191 A return value of \fBOK\fR combined with status of \fB1\fR in \fIerrret\fR
192 is normal.
193 .IP
194 If \fBERR\fR is returned, examine \fIerrret\fR:
195 .RS
196 .TP 5
197 .B 1
198 means that the terminal is hardcopy, cannot be used for curses applications.
199 .IP
200 \fBsetupterm\fP determines if the entry is a hardcopy type by
201 checking the \fBhc\fP (\fBhardcopy\fP) capability.
202 .TP 5
203 .B 0
204 means that the terminal could not be found,
205 or that it is a generic type,
206 having too little information for curses applications to run.
207 .IP
208 \fBsetupterm\fP determines if the entry is a generic type by
209 checking the \fBgn\fP (\fBgeneric\fP) capability.
210 .TP 5
211 .B \-1
212 means that the \fBterminfo\fR database could not be found.
213 .RE
214 .IP
215 If \fIerrret\fR is
216 null, \fBsetupterm\fR prints an error message upon finding an error
217 and exits.  Thus, the simplest call is:
218 .sp
219       \fBsetupterm((char *)0, 1, (int *)0);\fR,
220 .sp
221 which uses all the defaults and sends the output to \fBstdout\fR.
222 .RE
223 .PP
224 The \fBsetterm\fR routine was replaced by \fBsetupterm\fR.  The call:
225 .sp
226       \fBsetupterm(\fR\fIterm\fR\fB, 1, (int *)0)\fR
227 .sp
228 provides the same functionality as \fBsetterm(\fR\fIterm\fR\fB)\fR.
229 The \fBsetterm\fR routine is provided for BSD compatibility, and
230 is not recommended for new programs.
231 .\" ***************************************************************************
232 .SS The Terminal State
233 .PP
234 The \fBsetupterm\fR routine stores its information about the terminal
235 in a \fBTERMINAL\fP structure pointed to by the global variable \fBcur_term\fP.
236 If it detects an error,
237 or decides that the terminal is unsuitable (hardcopy or generic),
238 it discards this information,
239 making it not available to applications.
240 .PP
241 If \fBsetupterm\fP is called repeatedly for the same terminal type,
242 it will reuse the information.
243 It maintains only one copy of a given terminal's capabilities in memory.
244 If it is called for different terminal types,
245 \fBsetupterm\fP allocates new storage for each set of terminal capabilities.
246 .PP
247 The \fBset_curterm\fR routine sets \fBcur_term\fR to
248 \fInterm\fR, and makes all of the \fBterminfo\fR boolean, numeric, and
249 string variables use the values from \fInterm\fR.
250 It returns the old value of \fBcur_term\fR.
251 .PP
252 The \fBdel_curterm\fR routine frees the space pointed to by
253 \fIoterm\fR and makes it available for further use.  If \fIoterm\fR is
254 the same as \fBcur_term\fR, references to any of the \fBterminfo\fR
255 boolean, numeric, and string variables thereafter may refer to invalid
256 memory locations until another \fBsetupterm\fR has been called.
257 .PP
258 The \fBrestartterm\fR routine is similar to \fBsetupterm\fR and \fBinitscr\fR,
259 except that it is called after restoring memory to a previous state (for
260 example, when reloading a game saved as a core image dump).
261 \fBrestartterm\fP assumes that the windows and the input and output options
262 are the same as when memory was saved,
263 but the terminal type and baud rate may be different.
264 Accordingly, \fBrestartterm\fP saves various tty state bits,
265 calls \fBsetupterm\fP, and then restores the bits.
266 .\" ***************************************************************************
267 .SS Formatting Output
268 .PP
269 The \fBtparm\fR routine instantiates the string \fIstr\fR with
270 parameters \fIpi\fR.  A pointer is returned to the result of \fIstr\fR
271 with the parameters applied.
272 Application developers should keep in mind these quirks of the interface:
273 .bP
274 Although \fBtparm\fP's actual parameters may be integers or strings,
275 the prototype expects \fBlong\fP (integer) values.
276 .bP
277 Aside from the \fBset_attributes\fP (\fBsgr\fP) capability,
278 most terminal capabilities require no more than one or two parameters.
279 .PP
280 \fBtiparm\fP is a newer form of \fBtparm\fP which uses \fI<stdarg.h>\fP
281 rather than a fixed-parameter list.
282 Its numeric parameters are integers (int) rather than longs.
283 .\" ***************************************************************************
284 .SS Output Functions
285 .PP
286 The \fBtputs\fR routine applies padding information to the string
287 \fIstr\fR and outputs it:
288 .bP
289 The \fIstr\fR must be a terminfo string
290 variable or the return value from \fBtparm\fR, \fBtgetstr\fR, or
291 \fBtgoto\fR.
292 .bP
293 \fIaffcnt\fR is the number of lines affected, or 1 if
294 not applicable.
295 .bP
296 \fIputc\fR is a \fBputchar\fR-like routine to which
297 the characters are passed, one at a time.
298 .PP
299 The \fBputp\fR routine calls \fBtputs(\fR\fIstr\fR\fB, 1, putchar)\fR.
300 The output of \fBputp\fR always goes to \fBstdout\fR, rather than
301 the \fIfiledes\fR specified in \fBsetupterm\fR.
302 .PP
303 The \fBvidputs\fR routine displays the string on the terminal in the
304 video attribute mode \fIattrs\fR, which is any combination of the
305 attributes listed in \fBcurses\fR(3X).  The characters are passed to
306 the \fBputchar\fR-like routine \fIputc\fR.
307 .PP
308 The \fBvidattr\fR routine is like the \fBvidputs\fR routine, except
309 that it outputs through \fBputchar\fR.
310 .PP
311 The \fBvid_attr\fR and \fBvid_puts\fR routines correspond to vidattr and vidputs,
312 respectively.
313 They use a set of arguments for representing the video attributes plus color,
314 i.e.,
315 .bP
316 \fIattrs\fP of type \fBattr_t\fP for the attributes and
317 .bP
318 \fIpair\fP of type \fBshort\fP for the color-pair number.
319 .PP
320 The \fBvid_attr\fR and \fBvid_puts\fR routines
321 are designed to use the attribute constants with the \fIWA_\fR prefix.
322 .PP
323 X/Open Curses reserves the \fIopts\fP argument for future use,
324 saying that applications must provide a null pointer for that argument.
325 As an extension,
326 this implementation allows \fIopts\fP to be used as a pointer to \fBint\fP,
327 which overrides the \fIpair\fP (\fBshort\fP) argument.
328 .PP
329 The \fBmvcur\fR routine provides low-level cursor motion.  It takes
330 effect immediately (rather than at the next refresh).
331 .\" ***************************************************************************
332 .SS Terminal Capability Functions
333 .PP
334 The \fBtigetflag\fR, \fBtigetnum\fR and \fBtigetstr\fR routines return
335 the value of the capability corresponding to the \fBterminfo\fR
336 \fIcapname\fR passed to them, such as \fBxenl\fR.
337 The \fIcapname\fR for each capability is given in the table column entitled
338 \fIcapname\fR code in the capabilities section of \fBterminfo\fR(\*n).
339 .PP
340 These routines return special values to denote errors.
341 .PP
342 The \fBtigetflag\fR routine returns
343 .TP
344 \fB\-1\fR
345 if \fIcapname\fR is not a boolean capability,
346 or
347 .TP
348 \fB0\fR
349 if it is canceled or absent from the terminal description.
350 .PP
351 The \fBtigetnum\fR routine returns
352 .TP
353 \fB\-2\fR
354 if \fIcapname\fR is not a numeric capability, or
355 .TP
356 \fB\-1\fR
357 if it is canceled or absent from the terminal description.
358 .PP
359 The \fBtigetstr\fR routine returns
360 .TP
361 \fB(char *)\-1\fR
362 if \fIcapname\fR is not a string capability,
363 or
364 .TP
365 \fB0\fR
366 if it is canceled or absent from the terminal description.
367 .\" ***************************************************************************
368 .SS Terminal Capability Names
369 .PP
370 These null-terminated arrays contain
371 .bP
372 the short terminfo names (\*(``codes\*(''),
373 .bP
374 the \fBtermcap\fR names (\*(``names\*('', and
375 .bP
376 the long terminfo names (\*(``fnames\*('')
377 .PP
378 for each of the predefined \fBterminfo\fR variables:
379 .sp
380 .RS
381 \fBconst char *boolnames[]\fR, \fB*boolcodes[]\fR, \fB*boolfnames[]\fR
382 .br
383 \fBconst char *numnames[]\fR, \fB*numcodes[]\fR, \fB*numfnames[]\fR
384 .br
385 \fBconst char *strnames[]\fR, \fB*strcodes[]\fR, \fB*strfnames[]\fR
386 .RE
387 .SH RETURN VALUE
388 Routines that return an integer return \fBERR\fR upon failure and \fBOK\fR
389 (SVr4 only specifies \*(``an integer value other than \fBERR\fR\*('') upon successful
390 completion, unless otherwise noted in the preceding routine descriptions.
391 .PP
392 Routines that return pointers always return \fBNULL\fR on error.
393 .PP
394 X/Open defines no error conditions.
395 In this implementation
396 .RS 3
397 .TP 5
398 \fBdel_curterm\fP
399 returns an error
400 if its terminal parameter is null.
401 .TP 5
402 \fBputp\fP
403 calls \fBtputs\fP, returning the same error-codes.
404 .TP 5
405 \fBrestartterm\fP
406 returns an error
407 if the associated call to \fBsetupterm\fP returns an error.
408 .TP 5
409 \fBsetupterm\fP
410 returns an error
411 if it cannot allocate enough memory, or
412 create the initial windows (stdscr, curscr, newscr).
413 Other error conditions are documented above.
414 .TP 5
415 \fBtputs\fP
416 returns an error if the string parameter is null.
417 It does not detect I/O errors:
418 X/Open states that \fBtputs\fP ignores the return value
419 of the output function \fIputc\fP.
420 .RE
421 .SH PORTABILITY
422 .SS Legacy functions
423 .PP
424 X/Open notes that \fBvidattr\fR and \fBvidputs\fR may be macros.
425 .PP
426 The function \fBsetterm\fR is not described by X/Open and must
427 be considered non-portable.
428 All other functions are as described by X/Open.
429 .SS Legacy data
430 .PP
431 \fBsetupterm\fP copies the terminal name to the array \fBttytype\fP.
432 This is not part of X/Open Curses, but is assumed by some applications.
433 .PP
434 Other implementions may not declare the capability name arrays.
435 Some provide them without declaring them.
436 X/Open does not specify them.
437 .PP
438 Extended terminal capability names, e.g., as defined by \fB@TIC@\ \-x\fP,
439 are not stored in the arrays described here.
440 .SS Output buffering
441 .PP
442 Older versions of \fBncurses\fP assumed that the file descriptor passed to
443 \fBsetupterm\fP from \fBinitscr\fP or \fBnewterm\fP uses buffered I/O,
444 and would write to the corresponding stream.
445 In addition to the limitation that the terminal was left in block-buffered
446 mode on exit (like System V curses),
447 it was problematic because \fBncurses\fP
448 did not allow a reliable way to cleanup on receiving SIGTSTP.
449 .PP
450 The current version (ncurses6)
451 uses output buffers managed directly by \fBncurses\fP.
452 Some of the low-level functions described in this manual page write
453 to the standard output.
454 They are not signal-safe.
455 The high-level functions in \fBncurses\fP use
456 alternate versions of these functions
457 using the more reliable buffering scheme.
458 .SS Function prototypes
459 .PP
460 The X/Open Curses prototypes are based on the SVr4 curses header declarations,
461 which were defined at the same time the C language was first standardized in
462 the late 1980s.
463 .bP
464 X/Open Curses uses \fBconst\fP less effectively than a later design might,
465 in some cases applying it needlessly to values are already constant,
466 and in most cases overlooking parameters which normally would use \fBconst\fP.
467 Using constant parameters for functions which do not use \fBconst\fP
468 may prevent the program from compiling.
469 On the other hand, \fIwritable strings\fP are an obsolescent feature.
470 .IP
471 As an extension, this implementation can be configured to change the
472 function prototypes to use the \fBconst\fP keyword.
473 The ncurses ABI 6 enables this feature by default.
474 .bP
475 X/Open Curses prototypes \fBtparm\fR with a fixed number of parameters,
476 rather than a variable argument list.
477 .IP
478 This implementation uses a variable argument list, but can be
479 configured to use the fixed-parameter list.
480 Portable applications should provide 9 parameters after the format;
481 zeroes are fine for this purpose.
482 .IP
483 In response to review comments by Thomas E. Dickey,
484 X/Open Curses Issue 7 proposed the \fBtiparm\fP function in mid-2009.
485 .SS Special TERM treatment
486 .PP
487 If configured to use the terminal-driver,
488 e.g., for the MinGW port,
489 .bP
490 \fBsetupterm\fP interprets a missing/empty TERM variable as the
491 special value \*(``unknown\*(''.
492 .bP
493 \fBsetupterm\fP allows explicit use of the
494 the windows console driver by checking if $TERM is set to
495 \*(``#win32con\*('' or an abbreviation of that string.
496 .SS Other portability issues
497 .PP
498 In System V Release 4, \fBset_curterm\fR has an \fBint\fR return type and
499 returns \fBOK\fR or \fBERR\fR.  We have chosen to implement the X/Open Curses
500 semantics.
501 .PP
502 In System V Release 4, the third argument of \fBtputs\fR has the type
503 \fBint (*putc)(char)\fR.
504 .PP
505 At least one implementation of X/Open Curses (Solaris) returns a value
506 other than \fBOK\fP/\fBERR\fP from \fBtputs\fP.
507 That returns the length of the string, and does no error-checking.
508 .PP
509 X/Open notes that after calling \fBmvcur\fR, the curses state may not match the
510 actual terminal state, and that an application should touch and refresh
511 the window before resuming normal curses calls.
512 Both \fBncurses\fP and System V Release 4 curses implement \fBmvcur\fR using
513 the SCREEN data allocated in either \fBinitscr\fR or \fBnewterm\fR.
514 So though it is documented as a terminfo function,
515 \fBmvcur\fR is really a curses function which is not well specified.
516 .PP
517 X/Open states that the old location must be given for \fBmvcur\fP.
518 This implementation allows the caller to use \-1's for the old ordinates.
519 In that case, the old location is unknown.
520 .SH SEE ALSO
521 \fBcurses\fR(3X),
522 \fBcurs_initscr\fR(3X),
523 \fBcurs_kernel\fR(3X),
524 \fBcurs_termcap\fR(3X),
525 \fBcurs_variables\fR(3X),
526 \fBterm_variables\fR(3X),
527 \fBputc\fR(3),
528 \fBterminfo\fR(\*n)