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