]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_terminfo.3x
ncurses 6.4 - patch 20230423
[ncurses.git] / man / curs_terminfo.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2022,2023 Thomas E. Dickey                                *
3 .\" Copyright 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: curs_terminfo.3x,v 1.85 2023/04/23 20:52:38 tom Exp $
31 .TH curs_terminfo 3X ""
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de bP
37 .ie n  .IP \(bu 4
38 .el    .IP \(bu 2
39 ..
40 .ds n 5
41 .na
42 .hy 0
43 .SH NAME
44 \fBdel_curterm\fP,
45 \fBmvcur\fP,
46 \fBputp\fP,
47 \fBrestartterm\fP,
48 \fBset_curterm\fP,
49 \fBsetupterm\fP,
50 \fBtigetflag\fP,
51 \fBtigetnum\fP,
52 \fBtigetstr\fP,
53 \fBtiparm\fP,
54 \fBtiparm_s\fP,
55 \fBtiscan_s\fP,
56 \fBtparm\fP,
57 \fBtputs\fP,
58 \fBvid_attr\fP,
59 \fBvid_puts\fP,
60 \fBvidattr\fP,
61 \fBvidputs\fP \- \fBcurses\fP interfaces to terminfo database
62 .ad
63 .hy
64 .SH SYNOPSIS
65 .nf
66 \fB#include <curses.h>\fP
67 \fB#include <term.h>\fP
68 .sp
69 \fBTERMINAL *cur_term;\fP
70 .sp
71 \fBconst char * const boolnames[];\fP
72 \fBconst char * const boolcodes[];\fP
73 \fBconst char * const boolfnames[];\fP
74 \fBconst char * const numnames[];\fP
75 \fBconst char * const numcodes[];\fP
76 \fBconst char * const numfnames[];\fP
77 \fBconst char * const strnames[];\fP
78 \fBconst char * const strcodes[];\fP
79 \fBconst char * const strfnames[];\fP
80 .sp
81 \fBint setupterm(const char *\fIterm\fB, int \fIfiledes\fB, int *\fIerrret\fB);\fR
82 .br
83 \fBTERMINAL *set_curterm(TERMINAL *\fInterm\fB);\fR
84 .br
85 \fBint del_curterm(TERMINAL *\fIoterm\fB);\fR
86 .br
87 \fBint restartterm(const char *\fIterm\fB, int \fIfiledes\fB, int *\fIerrret\fB);\fR
88 .sp
89 \fBchar *tparm(const char *\fIstr\fB, ...);\fR
90 .br
91         \fIor\fP
92 .br
93 \fBchar *tparm(const char *\fIstr\fB, long \fIp1 ... \fBlong \fIp9\fB);\fR
94 .sp
95 \fBint tputs(const char *\fIstr\fB, int \fIaffcnt\fB, int (*\fIputc\fB)(int));\fR
96 .br
97 \fBint putp(const char *\fIstr\fB);\fR
98 .sp
99 \fBint vidputs(chtype \fIattrs\fB, int (*\fIputc\fB)(int));\fR
100 .br
101 \fBint vidattr(chtype \fIattrs\fB);\fR
102 .br
103 \fBint vid_puts(attr_t \fIattrs\fB, short \fIpair\fB, void *\fIopts\fB, int (*\fIputc\fB)(int));\fR
104 .br
105 \fBint vid_attr(attr_t \fIattrs\fB, short \fIpair\fB, void *\fIopts\fB);\fR
106 .sp
107 \fBint mvcur(int \fIoldrow\fB, int \fIoldcol\fB, int \fInewrow\fR, int \fInewcol\fB);\fR
108 .sp
109 \fBint tigetflag(const char *\fIcapname\fB);\fR
110 .br
111 \fBint tigetnum(const char *\fIcapname\fB);\fR
112 .br
113 \fBchar *tigetstr(const char *\fIcapname\fB);\fR
114 .sp
115 \fBchar *tiparm(const char *\fIstr\fB, ...);\fR
116 .sp
117 /* extensions */
118 .br
119 \fBchar *tiparm_s(int \fIexpected\fB, int \fImask\fB, const char *\fIstr\fB, ...);\fR
120 .br
121 \fBint tiscan_s(int *\fIexpected\fB, int *\fImask\fB, const char *\fIstr\fB);\fR
122 .br
123 .fi
124 .SH DESCRIPTION
125 These low-level routines must be called by programs that have to deal
126 directly with the \fBterminfo\fP database to handle certain terminal
127 capabilities, such as programming function keys.
128 For all other
129 functionality, \fBcurses\fP routines are more suitable and their use is
130 recommended.
131 .PP
132 None of these functions use (or are aware of) multibyte character strings
133 such as UTF-8:
134 .bP
135 capability names use the POSIX portable character set
136 .bP
137 capability string values have no associated encoding;
138 they are strings of 8-bit characters.
139 .SS Initialization
140 .PP
141 Initially, \fBsetupterm\fP should be called.
142 The high-level curses functions \fBinitscr\fP and
143 \fBnewterm\fP call \fBsetupterm\fP to initialize the
144 low-level set of terminal-dependent variables
145 [listed in \fBterminfo\fP(\*n)].
146 .PP
147 Applications can use the
148 terminal capabilities either directly (via header definitions),
149 or by special functions.
150 The header files \fBcurses.h\fP and \fBterm.h\fP should be included (in this
151 order) to get the definitions for these strings, numbers, and flags.
152 .PP
153 The \fBterminfo\fP variables
154 \fBlines\fP and \fBcolumns\fP are initialized by \fBsetupterm\fP as
155 follows:
156 .bP
157 If \fBuse_env(FALSE)\fP has been called, values for
158 \fBlines\fP and \fBcolumns\fP specified in \fBterminfo\fP are used.
159 .bP
160 Otherwise, if the environment variables \fBLINES\fP and \fBCOLUMNS\fP
161 exist, their values are used.
162 If these environment variables do not
163 exist and the program is running in a window, the current window size
164 is used.
165 Otherwise, if the environment variables do not exist, the
166 values for \fBlines\fP and \fBcolumns\fP specified in the
167 \fBterminfo\fP database are used.
168 .PP
169 Parameterized strings should be passed through \fBtparm\fP to instantiate them.
170 All \fBterminfo\fP strings
171 (including the output of \fBtparm\fP)
172 should be printed
173 with \fBtputs\fP or \fBputp\fP.
174 Call \fBreset_shell_mode\fP to restore the
175 tty modes before exiting [see \fBcurs_kernel\fP(3X)].
176 .PP
177 Programs which use
178 cursor addressing should
179 .bP
180 output \fBenter_ca_mode\fP upon startup and
181 .bP
182 output \fBexit_ca_mode\fP before exiting.
183 .PP
184 Programs which execute shell subprocesses should
185 .bP
186 call \fBreset_shell_mode\fP and
187 output \fBexit_ca_mode\fP before the shell
188 is called and
189 .bP
190 output \fBenter_ca_mode\fP and
191 call \fBreset_prog_mode\fP after returning from the shell.
192 .PP
193 The \fBsetupterm\fP routine reads in the \fBterminfo\fP database,
194 initializing the \fBterminfo\fP structures, but does not set up the
195 output virtualization structures used by \fBcurses\fP.
196 These are its parameters:
197 .RS 3
198 .TP 5
199 \fIterm\fP
200 is the terminal type, a character string.
201 If \fIterm\fP is null, the environment variable \fBTERM\fP is used.
202 .TP 5
203 \fIfiledes\fP
204 is the file descriptor used for all output.
205 .TP 5
206 \fIerrret\fP
207 points to an optional location where an error status can be returned to
208 the caller.
209 If \fIerrret\fP is not null,
210 then \fBsetupterm\fP returns \fBOK\fP or
211 \fBERR\fP and stores a status value in the integer pointed to by
212 \fIerrret\fP.
213 A return value of \fBOK\fP combined with status of \fB1\fP in \fIerrret\fP
214 is normal.
215 .IP
216 If \fBERR\fP is returned, examine \fIerrret\fP:
217 .RS
218 .TP 5
219 .B 1
220 means that the terminal is hardcopy, cannot be used for curses applications.
221 .IP
222 \fBsetupterm\fP determines if the entry is a hardcopy type by
223 checking the \fBhc\fP (\fBhardcopy\fP) capability.
224 .TP 5
225 .B 0
226 means that the terminal could not be found,
227 or that it is a generic type,
228 having too little information for curses applications to run.
229 .IP
230 \fBsetupterm\fP determines if the entry is a generic type by
231 checking the \fBgn\fP (\fBgeneric\fP) capability.
232 .TP 5
233 .B \-1
234 means that the \fBterminfo\fP database could not be found.
235 .RE
236 .IP
237 If \fIerrret\fP is
238 null, \fBsetupterm\fP prints an error message upon finding an error
239 and exits.
240 Thus, the simplest call is:
241 .sp
242       \fBsetupterm((char *)0, 1, (int *)0);\fP,
243 .sp
244 which uses all the defaults and sends the output to \fBstdout\fP.
245 .RE
246 .\" ***************************************************************************
247 .SS The Terminal State
248 .PP
249 The \fBsetupterm\fP routine stores its information about the terminal
250 in a \fBTERMINAL\fP structure pointed to by the global variable \fBcur_term\fP.
251 If it detects an error,
252 or decides that the terminal is unsuitable (hardcopy or generic),
253 it discards this information,
254 making it not available to applications.
255 .PP
256 If \fBsetupterm\fP is called repeatedly for the same terminal type,
257 it will reuse the information.
258 It maintains only one copy of a given terminal's capabilities in memory.
259 If it is called for different terminal types,
260 \fBsetupterm\fP allocates new storage for each set of terminal capabilities.
261 .PP
262 The \fBset_curterm\fP routine sets \fBcur_term\fP to
263 \fInterm\fP, and makes all of the \fBterminfo\fP boolean, numeric, and
264 string variables use the values from \fInterm\fP.
265 It returns the old value of \fBcur_term\fP.
266 .PP
267 The \fBdel_curterm\fP routine frees the space pointed to by
268 \fIoterm\fP and makes it available for further use.
269 If \fIoterm\fP is
270 the same as \fBcur_term\fP, references to any of the \fBterminfo\fP
271 boolean, numeric, and string variables thereafter may refer to invalid
272 memory locations until another \fBsetupterm\fP has been called.
273 .PP
274 The \fBrestartterm\fP routine is similar to \fBsetupterm\fP and \fBinitscr\fP,
275 except that it is called after restoring memory to a previous state (for
276 example, when reloading a game saved as a core image dump).
277 \fBrestartterm\fP assumes that the windows and the input and output options
278 are the same as when memory was saved,
279 but the terminal type and baud rate may be different.
280 Accordingly, \fBrestartterm\fP saves various tty state bits,
281 calls \fBsetupterm\fP, and then restores the bits.
282 .\" ***************************************************************************
283 .SS Formatting Output
284 .PP
285 The \fBtparm\fP routine instantiates the string \fIstr\fP with
286 parameters \fIpi\fP.  A pointer is returned to the result of \fIstr\fP
287 with the parameters applied.
288 Application developers should keep in mind these quirks of the interface:
289 .bP
290 Although \fBtparm\fP's actual parameters may be integers or strings,
291 the prototype expects \fBlong\fP (integer) values.
292 .bP
293 Aside from the \fBset_attributes\fP (\fBsgr\fP) capability,
294 most terminal capabilities require no more than one or two parameters.
295 .bP
296 Padding information is ignored by \fBtparm\fP;
297 it is interpreted by \fBtputs\fP.
298 .bP
299 The capability string is null-terminated.
300 Use \*(``\\200\*('' where an ASCII NUL is needed in the output.
301 .PP
302 \fBtiparm\fP is a newer form of \fBtparm\fP which uses \fI<stdarg.h>\fP
303 rather than a fixed-parameter list.
304 Its numeric parameters are integers (int) rather than longs.
305 .PP
306 Both \fBtparm\fP and \fBtiparm\fP assume that the application passes
307 parameters consistent with the terminal description.
308 Two extensions are provided as alternatives to deal with untrusted data:
309 .bP
310 \fBtiparm_s\fP is an extension which is a safer formatting function
311 than \fBtparm\fR or \fBtiparm\fR,
312 because it allows the developer to tell the curses
313 library how many parameters to expect in the parameter list,
314 and which may be string parameters.
315 .IP
316 The \fImask\fP parameter has one bit set for each of the parameters
317 (up to 9) which will be passed as char* rather than numbers.
318 .bP
319 The extension \fBtiscan_s\fP allows the application
320 to inspect a formatting capability to see what the curses library would assume.
321 .\" ***************************************************************************
322 .SS Output Functions
323 .PP
324 The \fBtputs\fP routine applies padding information
325 (i.e., by interpreting marker embedded in the terminfo capability
326 such as \*(``$<5>\*('' as 5 milliseconds)
327 to the string
328 \fIstr\fP and outputs it:
329 .bP
330 The \fIstr\fP parameter must be a terminfo string
331 variable or the return value from
332 \fBtparm\fP, \fBtiparm\fP, \fBtgetstr\fP, or \fBtgoto\fP.
333 .IP
334 The \fBtgetstr\fP and \fBtgoto\fP functions are part of the \fItermcap\fP
335 interface,
336 which happens to share this function name with the \fIterminfo\fP interface.
337 .bP
338 \fIaffcnt\fP is the number of lines affected, or 1 if
339 not applicable.
340 .bP
341 \fIputc\fP is a \fBputchar\fP-like routine to which
342 the characters are passed, one at a time.
343 .PP
344 The \fBputp\fR routine calls \fBtputs(\fIstr\fB, 1, putchar)\fR.
345 The output of \fBputp\fP always goes to \fBstdout\fP, rather than
346 the \fIfiledes\fP specified in \fBsetupterm\fP.
347 .PP
348 The \fBvidputs\fP routine displays the string on the terminal in the
349 video attribute mode \fIattrs\fP, which is any combination of the
350 attributes listed in \fBcurses\fP(3X).
351 The characters are passed to
352 the \fBputchar\fP-like routine \fIputc\fP.
353 .PP
354 The \fBvidattr\fP routine is like the \fBvidputs\fP routine, except
355 that it outputs through \fBputchar\fP.
356 .PP
357 The \fBvid_attr\fP and \fBvid_puts\fP routines correspond
358 to vidattr and vidputs, respectively.
359 They use a set of arguments for representing the video attributes plus color,
360 i.e.,
361 .bP
362 \fIattrs\fP of type \fBattr_t\fP for the attributes and
363 .bP
364 \fIpair\fP of type \fBshort\fP for the color-pair number.
365 .PP
366 The \fBvid_attr\fP and \fBvid_puts\fP routines
367 are designed to use the attribute constants with the \fBWA_\fP prefix.
368 .PP
369 X/Open Curses reserves the \fIopts\fP argument for future use,
370 saying that applications must provide a null pointer for that argument.
371 As an extension,
372 this implementation allows \fIopts\fP to be used as a pointer to \fBint\fP,
373 which overrides the \fIpair\fP (\fBshort\fP) argument.
374 .PP
375 The \fBmvcur\fP routine provides low-level cursor motion.
376 It takes effect immediately (rather than at the next refresh).
377 .PP
378 While \fBputp\fP and \fBmvcur\fP are low-level functions which
379 do not use the high-level curses state,
380 they are declared in \fB<curses.h>\fP because SystemV did this
381 (see \fIHISTORY\fP).
382 .\" ***************************************************************************
383 .SS Terminal Capability Functions
384 .PP
385 The \fBtigetflag\fP, \fBtigetnum\fP and \fBtigetstr\fP routines return
386 the value of the capability corresponding to the \fBterminfo\fP
387 \fIcapname\fP passed to them, such as \fBxenl\fP.
388 The \fIcapname\fP for each capability is given in the table column entitled
389 \fIcapname\fP code in the capabilities section of \fBterminfo\fP(\*n).
390 .PP
391 These routines return special values to denote errors.
392 .PP
393 The \fBtigetflag\fP routine returns
394 .TP
395 \fB\-1\fP
396 if \fIcapname\fP is not a boolean capability,
397 or
398 .TP
399 \fB0\fP
400 if it is canceled or absent from the terminal description.
401 .PP
402 The \fBtigetnum\fP routine returns
403 .TP
404 \fB\-2\fP
405 if \fIcapname\fP is not a numeric capability, or
406 .TP
407 \fB\-1\fP
408 if it is canceled or absent from the terminal description.
409 .PP
410 The \fBtigetstr\fP routine returns
411 .TP
412 \fB(char *)\-1\fP
413 if \fIcapname\fP is not a string capability,
414 or
415 .TP
416 \fB0\fP
417 if it is canceled or absent from the terminal description.
418 .\" ***************************************************************************
419 .SS Terminal Capability Names
420 .PP
421 These null-terminated arrays contain
422 .bP
423 the short terminfo names (\*(``codes\*(''),
424 .bP
425 the \fBtermcap\fP names (\*(``names\*(''), and
426 .bP
427 the long terminfo names (\*(``fnames\*('')
428 .PP
429 for each of the predefined \fBterminfo\fP variables:
430 .sp
431 .RS
432 \fBconst char *boolnames[]\fP, \fB*boolcodes[]\fP, \fB*boolfnames[]\fP
433 .br
434 \fBconst char *numnames[]\fP, \fB*numcodes[]\fP, \fB*numfnames[]\fP
435 .br
436 \fBconst char *strnames[]\fP, \fB*strcodes[]\fP, \fB*strfnames[]\fP
437 .RE
438 .\" ***************************************************************************
439 .SS Releasing Memory
440 Each successful call to \fBsetupterm\fP allocates memory to hold the terminal
441 description.
442 As a side-effect, it sets \fBcur_term\fP to point to this memory.
443 If an application calls
444 .sp
445         \fBdel_curterm(cur_term);\fP
446 .sp
447 the memory will be freed.
448 .PP
449 The formatting functions \fBtparm\fP and \fBtiparm\fP extend the storage
450 allocated by \fBsetupterm\fP: 
451 .bP
452 the \*(``static\*('' terminfo variables [a-z].
453 Before ncurses 6.3, those were shared by all screens.
454 With ncurses 6.3, those are allocated per screen.
455 See \fBterminfo\fP(\*n) for details.
456 .bP
457 to improve performance, ncurses 6.3 caches the result of analyzing terminfo
458 strings for their parameter types.
459 That is stored as a binary tree referenced from the \fBTERMINAL\fP structure.
460 .PP
461 The higher-level \fBinitscr\fP and \fBnewterm\fP functions use \fBsetupterm\fP.
462 Normally they do not free this memory, but it is possible to do that using
463 the \fBdelscreen\fP(3X) function.
464 .\" ***************************************************************************
465 .SH RETURN VALUE
466 Routines that return an integer return \fBERR\fP upon failure and \fBOK\fP
467 (SVr4 only specifies \*(``an integer value other than \fBERR\fP\*('')
468 upon successful completion,
469 unless otherwise noted in the preceding routine descriptions.
470 .PP
471 Routines that return pointers always return \fBNULL\fP on error.
472 .PP
473 X/Open defines no error conditions.
474 In this implementation
475 .RS 3
476 .TP 5
477 \fBdel_curterm\fP
478 returns an error
479 if its terminal parameter is null.
480 .TP 5
481 \fBputp\fP
482 calls \fBtputs\fP, returning the same error-codes.
483 .TP 5
484 \fBrestartterm\fP
485 returns an error
486 if the associated call to \fBsetupterm\fP returns an error.
487 .TP 5
488 \fBsetupterm\fP
489 returns an error
490 if it cannot allocate enough memory, or
491 create the initial windows (stdscr, curscr, newscr).
492 Other error conditions are documented above.
493 .TP 5
494 \fBtparm\fP
495 returns a null if the capability would require unexpected parameters,
496 e.g., too many, too few, or incorrect types
497 (strings where integers are expected, or vice versa).
498 .TP 5
499 \fBtputs\fP
500 returns an error if the string parameter is null.
501 It does not detect I/O errors:
502 X/Open states that \fBtputs\fP ignores the return value
503 of the output function \fIputc\fP.
504 .RE
505 .\" ***************************************************************************
506 .SS Compatibility macros
507 This implementation provides a few macros for compatibility with systems
508 before SVr4 (see \fIHISTORY\fP).
509 Those include
510 \fBcrmode\fP,
511 \fBfixterm\fP,
512 \fBgettmode\fP,
513 \fBnocrmode\fP,
514 \fBresetterm\fP,
515 \fBsaveterm\fP, and
516 \fBsetterm\fP.
517 .PP
518 In SVr4, those are found in \fB<curses.h>\fP,
519 but except for \fBsetterm\fP, are likewise macros.
520 The one function, \fBsetterm\fP, is mentioned in the manual page.
521 The manual page notes that the \fBsetterm\fP routine
522 was replaced by \fBsetupterm\fP, stating that the call:
523 .sp
524       \fBsetupterm(\fIterm\fB, 1, (int *)0)\fR
525 .sp
526 provides the same functionality as \fBsetterm(\fIterm\fB)\fR,
527 and is not recommended for new programs.
528 This implementation provides each of those symbols
529 as macros for BSD compatibility,
530 .\" ***************************************************************************
531 .SH HISTORY
532 .PP
533 SVr2 introduced the terminfo feature.
534 Its programming manual mentioned these low-level functions:
535 .TS
536 l l
537 _ _
538 l l.
539 \fBFunction\fP  \fBDescription\fP
540 fixterm restore tty to \*(``in curses\*('' state
541 gettmode        establish current tty modes
542 mvcur   low level cursor motion
543 putp    T{
544 utility function that uses \fBtputs\fP to send characters via \fBputchar\fP.
545 T}
546 resetterm       set tty modes to \*(``out of curses\*('' state
547 resetty reset tty flags to stored value
548 saveterm        save current modes as \*(``in curses\*('' state
549 savetty store current tty flags
550 setterm establish terminal with given type
551 setupterm       establish terminal with given type
552 tparm   instantiate a string expression with parameters
553 tputs   apply padding information to a string
554 vidattr like \fBvidputs\fP, but outputs through \fBputchar\fP
555 vidputs T{
556 output a string to put terminal in a specified video attribute mode
557 T}
558 .TE
559 .PP
560 The programming manual also mentioned
561 functions provided for termcap compatibility
562 (commenting that they \*(``may go away at a later date\*(''):
563 .TS
564 l l
565 _ _
566 l l.
567 \fBFunction\fP  \fBDescription\fP
568 tgetent look up termcap entry for given \fIname\fP
569 tgetflag        get boolean entry for given \fIid\fP
570 tgetnum get numeric entry for given \fIid\fP
571 tgetstr get string entry for given \fIid\fP
572 tgoto   apply parameters to given capability
573 tputs   T{
574 apply padding to capability, calling a function to put characters
575 T}
576 .TE
577 .PP
578 Early terminfo programs obtained capability values from the
579 \fBTERMINAL\fP structure initialized by \fBsetupterm\fP.
580 .PP
581 SVr3 extended terminfo by adding functions to retrieve capability values
582 (like the termcap interface),
583 and reusing tgoto and tputs:
584 .TS
585 l l
586 _ _
587 l l.
588 \fBFunction\fP  \fBDescription\fP
589 tigetflag       get boolean entry for given \fIid\fP
590 tigetnum        get numeric entry for given \fIid\fP
591 tigetstr        get string entry for given \fIid\fP
592 .TE
593 .PP
594 SVr3 also replaced several of the SVr2 terminfo functions
595 which had no counterpart in the termcap interface,
596 documenting them as obsolete:
597 .TS
598 l l
599 _ _
600 l l.
601 \fBFunction\fP  \fBReplaced by\fP
602 crmode  cbreak
603 fixterm reset_prog_mode
604 gettmode        N/A
605 nocrmode        nocbreak
606 resetterm       reset_shell_mode
607 saveterm        def_prog_mode
608 setterm setupterm
609 .TE
610 .PP
611 SVr3 kept the \fBmvcur\fP, \fBvidattr\fP and \fBvidputs\fP functions,
612 along with \fBputp\fP, \fBtparm\fP and \fBtputs\fP.
613 The latter were needed to support padding,
614 and handling functions such as \fBvidattr\fP
615 (which used more than the two parameters supported by \fBtgoto\fP).
616 .PP
617 SVr3 introduced the functions for switching between terminal
618 descriptions, e.g., \fBset_curterm\fP.
619 Some of that was incremental improvements to the SVr2 library:
620 .bP
621 The \fBTERMINAL\fP type definition was introduced in SVr3.01,
622 for the \fBterm\fP structure provided in SVr2.
623 .bP
624 The various global variables such as \fBboolnames\fP were mentioned
625 in the programming manual at this point,
626 though the variables were provided in SVr2.
627 .PP
628 SVr4 added the \fBvid_attr\fP and \fBvid_puts\fP functions.
629 .PP
630 There are other low-level functions declared in the curses header files
631 on Unix systems,
632 but none were documented.
633 The functions marked \*(``obsolete\*('' remained in use
634 by the Unix \fBvi\fP(1) editor.
635 .SH PORTABILITY
636 .SS Extensions
637 The functions marked as extensions were designed for \fBncurses\fP(3X),
638 and are not found in SVr4 curses, 4.4BSD curses,
639 or any other previous version of curses.
640 .PP
641 .SS Legacy functions
642 .PP
643 X/Open notes that \fBvidattr\fP and \fBvidputs\fP may be macros.
644 .PP
645 The function \fBsetterm\fP is not described by X/Open and must
646 be considered non-portable.
647 All other functions are as described by X/Open.
648 .SS Legacy data
649 .PP
650 \fBsetupterm\fP copies the terminal name to the array \fBttytype\fP.
651 This is not part of X/Open Curses, but is assumed by some applications.
652 .PP
653 Other implementions may not declare the capability name arrays.
654 Some provide them without declaring them.
655 X/Open does not specify them.
656 .PP
657 Extended terminal capability names, e.g., as defined by \fB@TIC@\ \-x\fP,
658 are not stored in the arrays described here.
659 .SS Output buffering
660 .PP
661 Older versions of \fBncurses\fP assumed that the file descriptor passed to
662 \fBsetupterm\fP from \fBinitscr\fP or \fBnewterm\fP uses buffered I/O,
663 and would write to the corresponding stream.
664 In addition to the limitation that the terminal was left in block-buffered
665 mode on exit (like System V curses),
666 it was problematic because \fBncurses\fP
667 did not allow a reliable way to cleanup on receiving SIGTSTP.
668 .PP
669 The current version (ncurses6)
670 uses output buffers managed directly by \fBncurses\fP.
671 Some of the low-level functions described in this manual page write
672 to the standard output.
673 They are not signal-safe.
674 The high-level functions in \fBncurses\fP use
675 alternate versions of these functions
676 using the more reliable buffering scheme.
677 .SS Function prototypes
678 .PP
679 The X/Open Curses prototypes are based on the SVr4 curses header declarations,
680 which were defined at the same time the C language was first standardized in
681 the late 1980s.
682 .bP
683 X/Open Curses uses \fBconst\fP less effectively than a later design might,
684 in some cases applying it needlessly to values are already constant,
685 and in most cases overlooking parameters which normally would use \fBconst\fP.
686 Using constant parameters for functions which do not use \fBconst\fP
687 may prevent the program from compiling.
688 On the other hand, \fIwritable strings\fP are an obsolescent feature.
689 .IP
690 As an extension, this implementation can be configured to change the
691 function prototypes to use the \fBconst\fP keyword.
692 The ncurses ABI 6 enables this feature by default.
693 .bP
694 X/Open Curses prototypes \fBtparm\fP with a fixed number of parameters,
695 rather than a variable argument list.
696 .IP
697 This implementation uses a variable argument list, but can be
698 configured to use the fixed-parameter list.
699 Portable applications should provide 9 parameters after the format;
700 zeroes are fine for this purpose.
701 .IP
702 In response to review comments by Thomas E. Dickey,
703 X/Open Curses Issue 7 proposed the \fBtiparm\fP function in mid-2009.
704 .IP
705 While \fBtiparm\fP is always provided in ncurses,
706 the older form is only available as a build-time configuration option.
707 If not specially configured, \fBtparm\fP is the same as \fBtiparm\fP.
708 .PP
709 Both forms of \fBtparm\fP have drawbacks:
710 .bP
711 Most of the calls to \fBtparm\fP use only one or two parameters.
712 Passing nine on each call is awkward.
713 .IP
714 Using \fBlong\fP for the numeric parameter type is a workaround
715 to make the parameter use the same amount of stack as a pointer.
716 That approach dates back to the mid-1980s, before C was standarized.
717 Since then, there is a standard
718 (and pointers are not required to fit in a long).
719 .bP
720 Providing the right number of parameters for a variadic function
721 such as \fBtiparm\fP can be a problem, in particular for string parameters.
722 However, only a few terminfo capabilities use string parameters
723 (e.g., the ones used for programmable function keys).
724 .IP
725 The ncurses library checks usage of these capabilities,
726 and returns an error if the capability mishandles string parameters.
727 But it cannot check if a calling program provides strings in the right
728 places for the \fBtparm\fP calls.
729 .IP
730 The \fB@TPUT@\fR(1) program checks its use of these capabilities with a table,
731 so that it calls \fBtparm\fP correctly.
732 .SS Special TERM treatment
733 .PP
734 If configured to use the terminal-driver,
735 e.g., for the MinGW port,
736 .bP
737 \fBsetupterm\fP interprets a missing/empty TERM variable as the
738 special value \*(``unknown\*(''.
739 .bP
740 \fBsetupterm\fP allows explicit use of the
741 the windows console driver by checking if $TERM is set to
742 \*(``#win32con\*('' or an abbreviation of that string.
743 .SS Other portability issues
744 .PP
745 In System V Release 4, \fBset_curterm\fP has an \fBint\fP return type and
746 returns \fBOK\fP or \fBERR\fP.  We have chosen to implement the X/Open Curses
747 semantics.
748 .PP
749 In System V Release 4, the third argument of \fBtputs\fP has the type
750 \fBint (*putc)(char)\fP.
751 .PP
752 At least one implementation of X/Open Curses (Solaris) returns a value
753 other than \fBOK\fP/\fBERR\fP from \fBtputs\fP.
754 That returns the length of the string, and does no error-checking.
755 .PP
756 X/Open notes that after calling \fBmvcur\fP, the curses state may not match the
757 actual terminal state, and that an application should touch and refresh
758 the window before resuming normal curses calls.
759 Both \fBncurses\fP and System V Release 4 curses implement \fBmvcur\fP using
760 the SCREEN data allocated in either \fBinitscr\fP or \fBnewterm\fP.
761 So though it is documented as a terminfo function,
762 \fBmvcur\fP is really a curses function which is not well specified.
763 .PP
764 X/Open states that the old location must be given for \fBmvcur\fP.
765 This implementation allows the caller to use \-1's for the old ordinates.
766 In that case, the old location is unknown.
767 .SH SEE ALSO
768 \fBcurses\fP(3X),
769 \fBcurs_initscr\fP(3X),
770 \fBcurs_kernel\fP(3X),
771 \fBcurs_memleaks\fP(3X),
772 \fBcurs_termcap\fP(3X),
773 \fBcurs_variables\fP(3X),
774 \fBterm_variables\fP(3X),
775 \fBputc\fP(3),
776 \fBterminfo\fP(\*n)