1 .\"***************************************************************************
2 .\" Copyright 2018-2020,2021 Thomas E. Dickey *
3 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc. *
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: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
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. *
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 *
28 .\"***************************************************************************
30 .\" $Id: curs_terminfo.3x,v 1.72 2021/01/02 23:50:04 tom Exp $
31 .TH curs_terminfo 3X ""
59 \fBvidputs\fR \- \fBcurses\fR interfaces to terminfo database
64 \fB#include <curses.h>\fR
65 \fB#include <term.h>\fR
67 \fBTERMINAL *cur_term;\fR
69 \fBconst char * const boolnames[];\fP
70 \fBconst char * const boolcodes[];\fP
71 \fBconst char * const boolfnames[];\fP
72 \fBconst char * const numnames[];\fP
73 \fBconst char * const numcodes[];\fP
74 \fBconst char * const numfnames[];\fP
75 \fBconst char * const strnames[];\fP
76 \fBconst char * const strcodes[];\fP
77 \fBconst char * const strfnames[];\fP
79 \fBint setupterm(const char *\fR\fIterm\fR\fB, int \fR\fIfiledes\fR\fB, int *\fR\fIerrret\fR\fB);\fR
81 \fBTERMINAL *set_curterm(TERMINAL *\fR\fInterm\fR\fB);\fR
83 \fBint del_curterm(TERMINAL *\fR\fIoterm\fR\fB);\fR
85 \fBint restartterm(const char *\fR\fIterm\fR\fB, int \fR\fIfiledes\fR\fB, int *\fR\fIerrret\fR\fB);\fR
87 \fBchar *tparm(const char *\fR\fIstr\fR\fB, ...);\fR
89 \fBint tputs(const char *\fR\fIstr\fR\fB, int \fR\fIaffcnt\fR\fB, int (*\fR\fIputc\fR\fB)(int));\fR
91 \fBint putp(const char *\fR\fIstr\fR\fB);\fR
93 \fBint vidputs(chtype \fR\fIattrs\fR\fB, int (*\fR\fIputc\fR\fB)(int));\fR
95 \fBint vidattr(chtype \fR\fIattrs\fR\fB);\fR
97 \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
99 \fBint vid_attr(attr_t \fR\fIattrs\fR\fB, short \fR\fIpair\fR\fB, void *\fR\fIopts\fR\fB);\fR
101 \fBint mvcur(int \fR\fIoldrow\fR\fB, int \fR\fIoldcol\fR\fB, int \fR\fInewrow\fR, int \fR\fInewcol\fR\fB);\fR
103 \fBint tigetflag(const char *\fR\fIcapname\fR\fB);\fR
105 \fBint tigetnum(const char *\fR\fIcapname\fR\fB);\fR
107 \fBchar *tigetstr(const char *\fR\fIcapname\fR\fB);\fR
109 \fBchar *tiparm(const char *\fR\fIstr\fR\fB, ...);\fR
113 These low-level routines must be called by programs that have to deal
114 directly with the \fBterminfo\fR database to handle certain terminal
115 capabilities, such as programming function keys.
117 functionality, \fBcurses\fR routines are more suitable and their use is
120 None of these functions use (or are aware of) multibyte character strings
123 capability names use the POSIX portable character set
125 capability string values have no associated encoding;
126 they are strings of 8-bit characters.
129 Initially, \fBsetupterm\fR should be called.
130 The high-level curses functions \fBinitscr\fR and
131 \fBnewterm\fR call \fBsetupterm\fP to initialize the
132 low-level set of terminal-dependent variables
133 [listed in \fBterminfo\fR(\*n)].
135 Applications can use the
136 terminal capabilities either directly (via header definitions),
137 or by special functions.
138 The header files \fBcurses.h\fR and \fBterm.h\fR should be included (in this
139 order) to get the definitions for these strings, numbers, and flags.
141 The \fBterminfo\fR variables
142 \fBlines\fR and \fBcolumns\fR are initialized by \fBsetupterm\fR as
145 If \fBuse_env(FALSE)\fR has been called, values for
146 \fBlines\fR and \fBcolumns\fR specified in \fBterminfo\fR are used.
148 Otherwise, if the environment variables \fBLINES\fR and \fBCOLUMNS\fR
149 exist, their values are used.
150 If these environment variables do not
151 exist and the program is running in a window, the current window size
153 Otherwise, if the environment variables do not exist, the
154 values for \fBlines\fR and \fBcolumns\fR specified in the
155 \fBterminfo\fR database are used.
157 Parameterized strings should be passed through \fBtparm\fR to instantiate them.
158 All \fBterminfo\fR strings
159 (including the output of \fBtparm\fR)
161 with \fBtputs\fR or \fBputp\fR.
162 Call \fBreset_shell_mode\fR to restore the
163 tty modes before exiting [see \fBcurs_kernel\fR(3X)].
166 cursor addressing should
168 output \fBenter_ca_mode\fR upon startup and
170 output \fBexit_ca_mode\fR before exiting.
172 Programs which execute shell subprocesses should
174 call \fBreset_shell_mode\fR and
175 output \fBexit_ca_mode\fR before the shell
178 output \fBenter_ca_mode\fR and
179 call \fBreset_prog_mode\fR after returning from the shell.
181 The \fBsetupterm\fR routine reads in the \fBterminfo\fR database,
182 initializing the \fBterminfo\fR structures, but does not set up the
183 output virtualization structures used by \fBcurses\fR.
184 These are its parameters:
188 is the terminal type, a character string.
189 If \fIterm\fR is null, the environment variable \fBTERM\fR is used.
192 is the file descriptor used for all output.
195 points to an optional location where an error status can be returned to
197 If \fIerrret\fR is not null,
198 then \fBsetupterm\fR returns \fBOK\fR or
199 \fBERR\fR and stores a status value in the integer pointed to by
201 A return value of \fBOK\fR combined with status of \fB1\fR in \fIerrret\fR
204 If \fBERR\fR is returned, examine \fIerrret\fR:
208 means that the terminal is hardcopy, cannot be used for curses applications.
210 \fBsetupterm\fP determines if the entry is a hardcopy type by
211 checking the \fBhc\fP (\fBhardcopy\fP) capability.
214 means that the terminal could not be found,
215 or that it is a generic type,
216 having too little information for curses applications to run.
218 \fBsetupterm\fP determines if the entry is a generic type by
219 checking the \fBgn\fP (\fBgeneric\fP) capability.
222 means that the \fBterminfo\fR database could not be found.
226 null, \fBsetupterm\fR prints an error message upon finding an error
228 Thus, the simplest call is:
230 \fBsetupterm((char *)0, 1, (int *)0);\fR,
232 which uses all the defaults and sends the output to \fBstdout\fR.
234 .\" ***************************************************************************
235 .SS The Terminal State
237 The \fBsetupterm\fR routine stores its information about the terminal
238 in a \fBTERMINAL\fP structure pointed to by the global variable \fBcur_term\fP.
239 If it detects an error,
240 or decides that the terminal is unsuitable (hardcopy or generic),
241 it discards this information,
242 making it not available to applications.
244 If \fBsetupterm\fP is called repeatedly for the same terminal type,
245 it will reuse the information.
246 It maintains only one copy of a given terminal's capabilities in memory.
247 If it is called for different terminal types,
248 \fBsetupterm\fP allocates new storage for each set of terminal capabilities.
250 The \fBset_curterm\fR routine sets \fBcur_term\fR to
251 \fInterm\fR, and makes all of the \fBterminfo\fR boolean, numeric, and
252 string variables use the values from \fInterm\fR.
253 It returns the old value of \fBcur_term\fR.
255 The \fBdel_curterm\fR routine frees the space pointed to by
256 \fIoterm\fR and makes it available for further use.
258 the same as \fBcur_term\fR, references to any of the \fBterminfo\fR
259 boolean, numeric, and string variables thereafter may refer to invalid
260 memory locations until another \fBsetupterm\fR has been called.
262 The \fBrestartterm\fR routine is similar to \fBsetupterm\fR and \fBinitscr\fR,
263 except that it is called after restoring memory to a previous state (for
264 example, when reloading a game saved as a core image dump).
265 \fBrestartterm\fP assumes that the windows and the input and output options
266 are the same as when memory was saved,
267 but the terminal type and baud rate may be different.
268 Accordingly, \fBrestartterm\fP saves various tty state bits,
269 calls \fBsetupterm\fP, and then restores the bits.
270 .\" ***************************************************************************
271 .SS Formatting Output
273 The \fBtparm\fR routine instantiates the string \fIstr\fR with
274 parameters \fIpi\fR. A pointer is returned to the result of \fIstr\fR
275 with the parameters applied.
276 Application developers should keep in mind these quirks of the interface:
278 Although \fBtparm\fP's actual parameters may be integers or strings,
279 the prototype expects \fBlong\fP (integer) values.
281 Aside from the \fBset_attributes\fP (\fBsgr\fP) capability,
282 most terminal capabilities require no more than one or two parameters.
284 \fBtiparm\fP is a newer form of \fBtparm\fP which uses \fI<stdarg.h>\fP
285 rather than a fixed-parameter list.
286 Its numeric parameters are integers (int) rather than longs.
287 .\" ***************************************************************************
290 The \fBtputs\fR routine applies padding information to the string
291 \fIstr\fR and outputs it:
293 The \fIstr\fR parameter must be a terminfo string
294 variable or the return value from
295 \fBtparm\fR, \fBtiparm\fP, \fBtgetstr\fR, or \fBtgoto\fR.
297 The \fBtgetstr\fP and \fBtgoto\fP functions are part of the \fItermcap\fP
299 which happens to share this function name with the \fIterminfo\fP interface.
301 \fIaffcnt\fR is the number of lines affected, or 1 if
304 \fIputc\fR is a \fBputchar\fR-like routine to which
305 the characters are passed, one at a time.
307 The \fBputp\fR routine calls \fBtputs(\fR\fIstr\fR\fB, 1, putchar)\fR.
308 The output of \fBputp\fR always goes to \fBstdout\fR, rather than
309 the \fIfiledes\fR specified in \fBsetupterm\fR.
311 The \fBvidputs\fR routine displays the string on the terminal in the
312 video attribute mode \fIattrs\fR, which is any combination of the
313 attributes listed in \fBcurses\fR(3X).
314 The characters are passed to
315 the \fBputchar\fR-like routine \fIputc\fR.
317 The \fBvidattr\fR routine is like the \fBvidputs\fR routine, except
318 that it outputs through \fBputchar\fR.
320 The \fBvid_attr\fR and \fBvid_puts\fR routines correspond
321 to vidattr and vidputs, respectively.
322 They use a set of arguments for representing the video attributes plus color,
325 \fIattrs\fP of type \fBattr_t\fP for the attributes and
327 \fIpair\fP of type \fBshort\fP for the color-pair number.
329 The \fBvid_attr\fR and \fBvid_puts\fR routines
330 are designed to use the attribute constants with the \fIWA_\fR prefix.
332 X/Open Curses reserves the \fIopts\fP argument for future use,
333 saying that applications must provide a null pointer for that argument.
335 this implementation allows \fIopts\fP to be used as a pointer to \fBint\fP,
336 which overrides the \fIpair\fP (\fBshort\fP) argument.
338 The \fBmvcur\fR routine provides low-level cursor motion.
339 It takes effect immediately (rather than at the next refresh).
341 While \fBputp\fR and \fBmvcur\fP are low-level functions which
342 do not use the high-level curses state,
343 they are declared in \fB<curses.h>\fP because SystemV did this
345 .\" ***************************************************************************
346 .SS Terminal Capability Functions
348 The \fBtigetflag\fR, \fBtigetnum\fR and \fBtigetstr\fR routines return
349 the value of the capability corresponding to the \fBterminfo\fR
350 \fIcapname\fR passed to them, such as \fBxenl\fR.
351 The \fIcapname\fR for each capability is given in the table column entitled
352 \fIcapname\fR code in the capabilities section of \fBterminfo\fR(\*n).
354 These routines return special values to denote errors.
356 The \fBtigetflag\fR routine returns
359 if \fIcapname\fR is not a boolean capability,
363 if it is canceled or absent from the terminal description.
365 The \fBtigetnum\fR routine returns
368 if \fIcapname\fR is not a numeric capability, or
371 if it is canceled or absent from the terminal description.
373 The \fBtigetstr\fR routine returns
376 if \fIcapname\fR is not a string capability,
380 if it is canceled or absent from the terminal description.
381 .\" ***************************************************************************
382 .SS Terminal Capability Names
384 These null-terminated arrays contain
386 the short terminfo names (\*(``codes\*(''),
388 the \fBtermcap\fR names (\*(``names\*(''), and
390 the long terminfo names (\*(``fnames\*('')
392 for each of the predefined \fBterminfo\fR variables:
395 \fBconst char *boolnames[]\fR, \fB*boolcodes[]\fR, \fB*boolfnames[]\fR
397 \fBconst char *numnames[]\fR, \fB*numcodes[]\fR, \fB*numfnames[]\fR
399 \fBconst char *strnames[]\fR, \fB*strcodes[]\fR, \fB*strfnames[]\fR
402 Routines that return an integer return \fBERR\fR upon failure and \fBOK\fR
403 (SVr4 only specifies \*(``an integer value other than \fBERR\fR\*('')
404 upon successful completion,
405 unless otherwise noted in the preceding routine descriptions.
407 Routines that return pointers always return \fBNULL\fR on error.
409 X/Open defines no error conditions.
410 In this implementation
415 if its terminal parameter is null.
418 calls \fBtputs\fP, returning the same error-codes.
422 if the associated call to \fBsetupterm\fP returns an error.
426 if it cannot allocate enough memory, or
427 create the initial windows (stdscr, curscr, newscr).
428 Other error conditions are documented above.
431 returns an error if the string parameter is null.
432 It does not detect I/O errors:
433 X/Open states that \fBtputs\fP ignores the return value
434 of the output function \fIputc\fP.
436 .\" ***************************************************************************
437 .SS Compatibility macros
438 This implementation provides a few macros for compatibility with systems
439 before SVr4 (see \fBHISTORY\fP).
449 In SVr4, those are found in \fB<curses.h>\fP,
450 but except for \fBsetterm\fR, are likewise macros.
451 The one function, \fBsetterm\fR, is mentioned in the manual page.
452 The manual page notes that the \fBsetterm\fR routine
453 was replaced by \fBsetupterm\fR, stating that the call:
455 \fBsetupterm(\fR\fIterm\fR\fB, 1, (int *)0)\fR
457 provides the same functionality as \fBsetterm(\fR\fIterm\fR\fB)\fR,
458 and is not recommended for new programs.
459 This implementation provides each of those symbols
460 as macros for BSD compatibility,
461 .\" ***************************************************************************
464 SVr2 introduced the terminfo feature.
465 Its programming manual mentioned these low-level functions:
470 \fBFunction\fR \fBDescription\fR
471 fixterm restore tty to \*(``in curses\*('' state
472 gettmode establish current tty modes
473 mvcur low level cursor motion
475 utility function that uses \fBtputs\fP to send characters via \fBputchar\fP.
477 resetterm set tty modes to \*(``out of curses\*('' state
478 resetty reset tty flags to stored value
479 saveterm save current modes as \*(``in curses\*('' state
480 savetty store current tty flags
481 setterm establish terminal with given type
482 setupterm establish terminal with given type
483 tparm instantiate a string expression with parameters
484 tputs apply padding information to a string
485 vidattr like \fBvidputs\fP, but outputs through \fBputchar\fP
487 output a string to put terminal in a specified video attribute mode
491 The programming manual also mentioned
492 functions provided for termcap compatibility
493 (commenting that they \*(``may go away at a later date\*(''):
498 \fBFunction\fR \fBDescription\fR
499 tgetent look up termcap entry for given \fIname\fP
500 tgetflag get boolean entry for given \fIid\fP
501 tgetnum get numeric entry for given \fIid\fP
502 tgetstr get string entry for given \fIid\fP
503 tgoto apply parameters to given capability
505 apply padding to capability, calling a function to put characters
509 Early terminfo programs obtained capability values from the
510 \fBTERMINAL\fP structure initialized by \fBsetupterm\fR.
512 SVr3 extended terminfo by adding functions to retrieve capability values
513 (like the termcap interface),
514 and reusing tgoto and tputs:
519 \fBFunction\fR \fBDescription\fR
520 tigetflag get boolean entry for given \fIid\fP
521 tigetnum get numeric entry for given \fIid\fP
522 tigetstr get string entry for given \fIid\fP
525 SVr3 also replaced several of the SVr2 terminfo functions
526 which had no counterpart in the termcap interface,
527 documenting them as obsolete:
532 \fBFunction\fR \fBReplaced by\fP
534 fixterm reset_prog_mode
537 resetterm reset_shell_mode
538 saveterm def_prog_mode
542 SVr3 kept the \fBmvcur\fP, \fBvidattr\fP and \fBvidputs\fP functions,
543 along with \fBputp\fP, \fBtparm\fP and \fBtputs\fP.
544 The latter were needed to support padding,
545 and handling functions such as \fBvidattr\fP
546 (which used more than the two parameters supported by \fBtgoto\fP).
548 SVr3 introduced the functions for switching between terminal
549 descriptions, e.g., \fBset_curterm\fP.
550 The various global variables such as \fBboolnames\fP were mentioned
551 in the programming manual at this point.
553 SVr4 added the \fBvid_attr\fP and \fBvid_puts\fP functions.
555 There are other low-level functions declared in the curses header files
557 but none were documented.
558 The functions marked \*(``obsolete\*('' remained in use
559 by the Unix \fBvi\fP editor.
563 X/Open notes that \fBvidattr\fR and \fBvidputs\fR may be macros.
565 The function \fBsetterm\fR is not described by X/Open and must
566 be considered non-portable.
567 All other functions are as described by X/Open.
570 \fBsetupterm\fP copies the terminal name to the array \fBttytype\fP.
571 This is not part of X/Open Curses, but is assumed by some applications.
573 Other implementions may not declare the capability name arrays.
574 Some provide them without declaring them.
575 X/Open does not specify them.
577 Extended terminal capability names, e.g., as defined by \fB@TIC@\ \-x\fP,
578 are not stored in the arrays described here.
581 Older versions of \fBncurses\fP assumed that the file descriptor passed to
582 \fBsetupterm\fP from \fBinitscr\fP or \fBnewterm\fP uses buffered I/O,
583 and would write to the corresponding stream.
584 In addition to the limitation that the terminal was left in block-buffered
585 mode on exit (like System V curses),
586 it was problematic because \fBncurses\fP
587 did not allow a reliable way to cleanup on receiving SIGTSTP.
589 The current version (ncurses6)
590 uses output buffers managed directly by \fBncurses\fP.
591 Some of the low-level functions described in this manual page write
592 to the standard output.
593 They are not signal-safe.
594 The high-level functions in \fBncurses\fP use
595 alternate versions of these functions
596 using the more reliable buffering scheme.
597 .SS Function prototypes
599 The X/Open Curses prototypes are based on the SVr4 curses header declarations,
600 which were defined at the same time the C language was first standardized in
603 X/Open Curses uses \fBconst\fP less effectively than a later design might,
604 in some cases applying it needlessly to values are already constant,
605 and in most cases overlooking parameters which normally would use \fBconst\fP.
606 Using constant parameters for functions which do not use \fBconst\fP
607 may prevent the program from compiling.
608 On the other hand, \fIwritable strings\fP are an obsolescent feature.
610 As an extension, this implementation can be configured to change the
611 function prototypes to use the \fBconst\fP keyword.
612 The ncurses ABI 6 enables this feature by default.
614 X/Open Curses prototypes \fBtparm\fR with a fixed number of parameters,
615 rather than a variable argument list.
617 This implementation uses a variable argument list, but can be
618 configured to use the fixed-parameter list.
619 Portable applications should provide 9 parameters after the format;
620 zeroes are fine for this purpose.
622 In response to review comments by Thomas E. Dickey,
623 X/Open Curses Issue 7 proposed the \fBtiparm\fP function in mid-2009.
624 .SS Special TERM treatment
626 If configured to use the terminal-driver,
627 e.g., for the MinGW port,
629 \fBsetupterm\fP interprets a missing/empty TERM variable as the
630 special value \*(``unknown\*(''.
632 \fBsetupterm\fP allows explicit use of the
633 the windows console driver by checking if $TERM is set to
634 \*(``#win32con\*('' or an abbreviation of that string.
635 .SS Other portability issues
637 In System V Release 4, \fBset_curterm\fR has an \fBint\fR return type and
638 returns \fBOK\fR or \fBERR\fR. We have chosen to implement the X/Open Curses
641 In System V Release 4, the third argument of \fBtputs\fR has the type
642 \fBint (*putc)(char)\fR.
644 At least one implementation of X/Open Curses (Solaris) returns a value
645 other than \fBOK\fP/\fBERR\fP from \fBtputs\fP.
646 That returns the length of the string, and does no error-checking.
648 X/Open notes that after calling \fBmvcur\fR, the curses state may not match the
649 actual terminal state, and that an application should touch and refresh
650 the window before resuming normal curses calls.
651 Both \fBncurses\fP and System V Release 4 curses implement \fBmvcur\fR using
652 the SCREEN data allocated in either \fBinitscr\fR or \fBnewterm\fR.
653 So though it is documented as a terminfo function,
654 \fBmvcur\fR is really a curses function which is not well specified.
656 X/Open states that the old location must be given for \fBmvcur\fP.
657 This implementation allows the caller to use \-1's for the old ordinates.
658 In that case, the old location is unknown.
661 \fBcurs_initscr\fR(3X),
662 \fBcurs_kernel\fR(3X),
663 \fBcurs_termcap\fR(3X),
664 \fBcurs_variables\fR(3X),
665 \fBterm_variables\fR(3X),