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