]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_terminfo.3x
22ed0777b15d9e08df27bb61d501968a24cda187
[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.95 2023/08/19 20:37:54 tom Exp $
32 .TH curs_terminfo 3X 2023-08-19 "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 .PP
539 .TS
540 l l.
541 \fBFunction\fP  \fBDescription\fP
542 _
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 .PP
567 .TS
568 l l
569 _ _
570 l l.
571 \fBFunction\fP  \fBDescription\fP
572 tgetent look up termcap entry for given \fIname\fP
573 tgetflag        get boolean entry for given \fIid\fP
574 tgetnum get numeric entry for given \fIid\fP
575 tgetstr get string entry for given \fIid\fP
576 tgoto   apply parameters to given capability
577 tputs   T{
578 apply padding to capability, calling a function to put characters
579 T}
580 .TE
581 .PP
582 Early terminfo programs obtained capability values from the
583 \fBTERMINAL\fP structure initialized by \fBsetupterm\fP.
584 .PP
585 SVr3 extended terminfo by adding functions to retrieve capability values
586 (like the termcap interface),
587 and reusing tgoto and tputs:
588 .PP
589 .TS
590 l l
591 _ _
592 l l.
593 \fBFunction\fP  \fBDescription\fP
594 tigetflag       get boolean entry for given \fIid\fP
595 tigetnum        get numeric entry for given \fIid\fP
596 tigetstr        get string entry for given \fIid\fP
597 .TE
598 .PP
599 SVr3 also replaced several of the SVr2 terminfo functions
600 which had no counterpart in the termcap interface,
601 documenting them as obsolete:
602 .TS
603 l l
604 _ _
605 l l.
606 \fBFunction\fP  \fBReplaced by\fP
607 crmode  cbreak
608 fixterm reset_prog_mode
609 gettmode        N/A
610 nocrmode        nocbreak
611 resetterm       reset_shell_mode
612 saveterm        def_prog_mode
613 setterm setupterm
614 .TE
615 .PP
616 SVr3 kept the \fBmvcur\fP, \fBvidattr\fP and \fBvidputs\fP functions,
617 along with \fBputp\fP, \fBtparm\fP and \fBtputs\fP.
618 The latter were needed to support padding,
619 and handling functions such as \fBvidattr\fP
620 (which used more than the two parameters supported by \fBtgoto\fP).
621 .PP
622 SVr3 introduced the functions for switching between terminal
623 descriptions, e.g., \fBset_curterm\fP.
624 Some of that was incremental improvements to the SVr2 library:
625 .bP
626 The \fBTERMINAL\fP type definition was introduced in SVr3.01,
627 for the \fBterm\fP structure provided in SVr2.
628 .bP
629 The various global variables such as \fBboolnames\fP were mentioned
630 in the programming manual at this point,
631 though the variables were provided in SVr2.
632 .PP
633 SVr4 added the \fBvid_attr\fP and \fBvid_puts\fP functions.
634 .PP
635 There are other low-level functions declared in the curses header files
636 on Unix systems,
637 but none were documented.
638 The functions marked \*(``obsolete\*('' remained in use
639 by the Unix \fBvi\fP(1) editor.
640 .SH PORTABILITY
641 .SS Extensions
642 The functions marked as extensions were designed for \fBncurses\fP(3X),
643 and are not found in SVr4 curses, 4.4BSD curses,
644 or any other previous version of curses.
645 .SS Legacy functions
646 X/Open notes that \fBvidattr\fP and \fBvidputs\fP may be macros.
647 .PP
648 The function \fBsetterm\fP is not described by X/Open and must
649 be considered non-portable.
650 All other functions are as described by X/Open.
651 .SS Legacy data
652 \fBsetupterm\fP copies the terminal name to the array \fBttytype\fP.
653 This is not part of X/Open Curses, but is assumed by some applications.
654 .PP
655 Other implementions may not declare the capability name arrays.
656 Some provide them without declaring them.
657 X/Open does not specify them.
658 .PP
659 Extended terminal capability names, e.g., as defined by \fB@TIC@\ \-x\fP,
660 are not stored in the arrays described here.
661 .SS Output buffering
662 Older versions of \fBncurses\fP assumed that the file descriptor passed to
663 \fBsetupterm\fP from \fBinitscr\fP or \fBnewterm\fP uses buffered I/O,
664 and would write to the corresponding stream.
665 In addition to the limitation that the terminal was left in block-buffered
666 mode on exit (like System V curses),
667 it was problematic because \fBncurses\fP
668 did not allow a reliable way to cleanup on receiving SIGTSTP.
669 .PP
670 The current version (ncurses6)
671 uses output buffers managed directly by \fBncurses\fP.
672 Some of the low-level functions described in this manual page write
673 to the standard output.
674 They are not signal-safe.
675 The high-level functions in \fBncurses\fP use
676 alternate versions of these functions
677 using the more reliable buffering scheme.
678 .SS Function prototypes
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 standardized.
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 If configured to use the terminal-driver,
734 e.g., for the MinGW port,
735 .bP
736 \fBsetupterm\fP interprets a missing/empty TERM variable as the
737 special value \*(``unknown\*(''.
738 .IP
739 SVr4 curses uses the
740 special value \*(``dumb\*(''.
741 .IP
742 The difference between the two is that
743 the former uses the \fBgn\fP (\fBgeneric_type\fR) terminfo capability,
744 while the latter does not.
745 A generic terminal is unsuitable for full-screen applications.
746 .bP
747 \fBsetupterm\fP allows explicit use of the
748 the windows console driver by checking if $TERM is set to
749 \*(``#win32con\*('' or an abbreviation of that string.
750 .SS Other portability issues
751 In System V Release 4, \fBset_curterm\fP has an \fBint\fP return type and
752 returns \fBOK\fP or \fBERR\fP.  We have chosen to implement the X/Open Curses
753 semantics.
754 .PP
755 In System V Release 4, the third argument of \fBtputs\fP has the type
756 \fBint (*putc)(char)\fP.
757 .PP
758 At least one implementation of X/Open Curses (Solaris) returns a value
759 other than \fBOK\fP/\fBERR\fP from \fBtputs\fP.
760 That returns the length of the string, and does no error-checking.
761 .PP
762 X/Open notes that after calling \fBmvcur\fP, the curses state may not match the
763 actual terminal state, and that an application should touch and refresh
764 the window before resuming normal curses calls.
765 Both \fBncurses\fP and System V Release 4 curses implement \fBmvcur\fP using
766 the SCREEN data allocated in either \fBinitscr\fP or \fBnewterm\fP.
767 So though it is documented as a terminfo function,
768 \fBmvcur\fP is really a curses function which is not well specified.
769 .PP
770 X/Open states that the old location must be given for \fBmvcur\fP.
771 This implementation allows the caller to use \-1's for the old ordinates.
772 In that case, the old location is unknown.
773 .SH SEE ALSO
774 \fBcurses\fP(3X),
775 \fBcurs_initscr\fP(3X),
776 \fBcurs_kernel\fP(3X),
777 \fBcurs_memleaks\fP(3X),
778 \fBcurs_termcap\fP(3X),
779 \fBcurs_variables\fP(3X),
780 \fBterm_variables\fP(3X),
781 \fBputc\fP(3),
782 \fBterminfo\fP(\*n)