]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_terminfo.3x
e5affc46f87fe5be78675acec0a43eba2932c20d
[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.125 2023/12/30 23:46:56 tom Exp $
32 .TH curs_terminfo 3X 2023-12-30 "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 \fI\%term\%info\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
121 .I \%term\%info
122 database to handle certain terminal capabilities,
123 such as programming function keys.
124 For all other functionality,
125 .I curses
126 routines are more suitable and their use is recommended.
127 .PP
128 None of these functions use
129 (or are aware of)
130 multibyte character strings such as UTF-8.
131 .bP
132 Capability names and codes use the POSIX portable character set.
133 .bP
134 Capability string values have no associated encoding;
135 they are strings of 8-bit characters.
136 .SS Initialization
137 Initially,
138 \fB\%setupterm\fP should be called.
139 The high-level
140 .I curses
141 functions \fB\%initscr\fP and \fB\%newterm\fP call \fB\%setupterm\fP to
142 initialize the low-level set of terminal-dependent variables
143 listed in \fB\%term_variables\fP(3X).
144 .PP
145 Applications can use the
146 terminal capabilities either directly
147 (via header definitions),
148 or by special functions.
149 The header files
150 .I \%curses.h
151 and
152 .I \%term.h
153 should be included
154 (in that order)
155 to get the definitions for these strings, numbers, and flags.
156 .PP
157 The
158 .I \%term\%info
159 variables
160 \fBlines\fP and \fBcolumns\fP are initialized by \fB\%setupterm\fP as
161 follows:
162 .bP
163 If \fB\%use_env(FALSE)\fP has been called,
164 values for \fBlines\fP and \fBcolumns\fP specified in
165 .I \%term\%info
166 are used.
167 .bP
168 Otherwise,
169 if the environment variables \fILINES\fP and \fI\%COLUMNS\fP exist,
170 their values are used.
171 If these environment variables do not
172 exist and the program is running in a window, the current window size
173 is used.
174 Otherwise, if the environment variables do not exist, the
175 values for \fBlines\fP and \fBcolumns\fP specified in the
176 .I \%term\%info
177 database are used.
178 .PP
179 Parameterized strings should be passed through \fBtparm\fP to instantiate them.
180 All
181 .I \%term\%info
182 strings
183 (including the output of \fBtparm\fP)
184 should be printed
185 with \fBtputs\fP or \fBputp\fP.
186 Call \fBreset_shell_mode\fP to restore the
187 tty modes before exiting [see \fBcurs_kernel\fP(3X)].
188 .PP
189 Programs which use
190 cursor addressing should
191 .bP
192 output \fBenter_ca_mode\fP upon startup and
193 .bP
194 output \fBexit_ca_mode\fP before exiting.
195 .PP
196 Programs which execute shell subprocesses should
197 .bP
198 call \fBreset_shell_mode\fP and
199 output \fBexit_ca_mode\fP before the shell
200 is called and
201 .bP
202 output \fBenter_ca_mode\fP and
203 call \fBreset_prog_mode\fP after returning from the shell.
204 .PP
205 The \fB\%setupterm\fP routine reads in the
206 .I \%term\%info
207 database,
208 initializing the
209 .I \%term\%info
210 structures,
211 but does not set up the output virtualization structures used by
212 .I curses.
213 These are its parameters:
214 .RS 3
215 .TP 5
216 \fIterm\fP
217 is the terminal type, a character string.
218 If \fIterm\fP is null,
219 the environment variable \fITERM\fP is used.
220 .TP 5
221 \fIfiledes\fP
222 is the file descriptor used for getting and setting terminal I/O modes.
223 .IP
224 Higher-level applications use \fBnewterm\fP(3X) for initializing the terminal,
225 passing an output \fIstream\fP rather than a \fIdescriptor\fP.
226 In curses, the two are the same because \fBnewterm\fP calls \fBsetupterm\fP,
227 passing the file descriptor derived from its output stream parameter.
228 .TP 5
229 \fIerrret\fP
230 points to an optional location where an error status can be returned to
231 the caller.
232 If \fIerrret\fP is not null,
233 then \fBsetupterm\fP returns \fBOK\fP or
234 \fBERR\fP and stores a status value in the integer pointed to by
235 \fIerrret\fP.
236 A return value of \fBOK\fP combined with status of \fB1\fP in \fIerrret\fP
237 is normal.
238 .IP
239 If \fBERR\fP is returned, examine \fIerrret\fP:
240 .RS
241 .TP 5
242 .B 1
243 means that the terminal is hardcopy, cannot be used
244 for \fIcurses\fP applications.
245 .IP
246 \fB\%setupterm\fP determines if the entry is a hardcopy type by
247 checking the \fBhc\fP (\fBhardcopy\fP) capability.
248 .TP 5
249 .B 0
250 means that the terminal could not be found,
251 or that it is a generic type,
252 having too little information for \fIcurses\fP applications to run.
253 .IP
254 \fB\%setupterm\fP determines if the entry is a generic type by
255 checking the \fBgn\fP \%(\fBgeneric_type\fP) capability.
256 .TP 5
257 .B \-1
258 means that the
259 .I \%term\%info
260 database could not be found.
261 .RE
262 .IP
263 If \fIerrret\fP is
264 null, \fB\%setupterm\fP prints an error message upon finding an error
265 and exits.
266 Thus, the simplest call is:
267 .RS
268 .IP
269 \fBsetupterm((char *)0, 1, (int *)0);\fP
270 .RE
271 .IP
272 which uses all the defaults and sends the output to \fBstdout\fP.
273 .RE
274 .\" ***************************************************************************
275 .SS "The Terminal State"
276 The \fBsetupterm\fP routine stores its information about the terminal
277 in a \fI\%TERMINAL\fP structure pointed to by the global variable \fBcur_term\fP.
278 If it detects an error,
279 or decides that the terminal is unsuitable (hardcopy or generic),
280 it discards this information,
281 making it not available to applications.
282 .PP
283 If \fBsetupterm\fP is called repeatedly for the same terminal type,
284 it will reuse the information.
285 It maintains only one copy of a given terminal's capabilities in memory.
286 If it is called for different terminal types,
287 \fBsetupterm\fP allocates new storage for each set of terminal capabilities.
288 .PP
289 \fB\%set_curterm\fP sets \fB\%cur_term\fP to
290 .I \%nterm,
291 and makes all of the
292 .I \%term\%info
293 Boolean,
294 numeric,
295 and string variables use the values from
296 .I \%nterm.
297 It returns the old value of \fB\%cur_term\fP.
298 .PP
299 \fB\%del_curterm\fP routine frees the space pointed to by
300 .I \%oterm
301 and makes it available for further use.
302 If
303 .I \%oterm
304 is
305 the same as \fB\%cur_term\fP,
306 references to any of the
307 .I \%term\%info
308 Boolean,
309 numeric,
310 and string variables thereafter may refer to invalid memory locations
311 until another \fB\%setupterm\fP has been called.
312 .PP
313 The \fBrestartterm\fP routine is similar to \fBsetupterm\fP and \fBinitscr\fP,
314 except that it is called after restoring memory to a previous state (for
315 example, when reloading a game saved as a core image dump).
316 \fBrestartterm\fP assumes that the windows and the input and output options
317 are the same as when memory was saved,
318 but the terminal type and baud rate may be different.
319 Accordingly, \fBrestartterm\fP saves various tty state bits,
320 calls \fBsetupterm\fP, and then restores the bits.
321 .\" ***************************************************************************
322 .SS "Formatting Output"
323 The \fBtparm\fP routine instantiates the string \fIstr\fP with
324 parameters \fIpi\fP.  A pointer is returned to the result of \fIstr\fP
325 with the parameters applied.
326 Application developers should keep in mind these quirks of the interface:
327 .bP
328 Although \fBtparm\fP's actual parameters may be integers or strings,
329 the prototype expects \fBlong\fP (integer) values.
330 .bP
331 Aside from the \fBset_attributes\fP (\fBsgr\fP) capability,
332 most terminal capabilities require no more than one or two parameters.
333 .bP
334 Padding information is ignored by \fBtparm\fP;
335 it is interpreted by \fBtputs\fP.
336 .bP
337 The capability string is null-terminated.
338 Use \*(``\e200\*('' where an ASCII NUL is needed in the output.
339 .PP
340 \fB\%tiparm\fP is a newer form of \fB\%tparm\fP which uses
341 .I \%stdarg.h
342 rather than a fixed-parameter list.
343 Its numeric parameters are
344 .IR int s
345 rather than
346 .IR long s.
347 .PP
348 Both \fBtparm\fP and \fBtiparm\fP assume that the application passes
349 parameters consistent with the terminal description.
350 Two extensions are provided as alternatives to deal with untrusted data:
351 .bP
352 \fBtiparm_s\fP is an extension which is a safer formatting function
353 than \fBtparm\fR or \fBtiparm\fR,
354 because it allows the developer to tell the curses
355 library how many parameters to expect in the parameter list,
356 and which may be string parameters.
357 .IP
358 The \fImask\fP parameter has one bit set for each of the parameters
359 (up to 9) which will be passed as char* rather than numbers.
360 .bP
361 The extension \fBtiscan_s\fP allows the application
362 to inspect a formatting capability to see what the curses library would assume.
363 .\" ***************************************************************************
364 .SS "Output Functions"
365 String capabilities can contain padding information,
366 a time delay
367 (accommodating performance limitations of hardware terminals)
368 expressed as \fB$<\fIn\fB>\fR,
369 where \fIn\fP is a nonnegative integral count of milliseconds.
370 If \fIn\fP exceeds 30,000
371 (thirty seconds),
372 it is capped at that value.
373 .PP
374 The \fBtputs\fP routine interprets time-delay information in the string
375 \fIstr\fP and outputs it, executing the delays:
376 .bP
377 The \fIstr\fP parameter must be a terminfo string
378 variable or the return value from
379 \fBtparm\fP, \fBtiparm\fP, \fBtgetstr\fP, or \fBtgoto\fP.
380 .IP
381 The \fBtgetstr\fP and \fBtgoto\fP functions are part of the \fItermcap\fP
382 interface,
383 which happens to share this function name with the
384 .I \%term\%info
385 interface.
386 .bP
387 \fIaffcnt\fP is the number of lines affected, or 1 if
388 not applicable.
389 .bP
390 \fIputc\fP is a \fI\%putchar\fP-like function to which
391 the characters are passed, one at a time.
392 .IP
393 If \fBtputs\fP processes a time-delay,
394 it uses the \fBdelay_output\fP(3X) function,
395 routing any resulting padding characters through this function.
396 .PP
397 The \fBputp\fR routine calls \fBtputs(\fIstr\fB, 1, \%putchar)\fR.
398 The output of \fBputp\fP always goes to \fBstdout\fP, rather than
399 the \fIfiledes\fP specified in \fBsetupterm\fP.
400 .PP
401 The \fBvidputs\fP routine displays the string on the terminal in the
402 video attribute mode \fIattrs\fP, which is any combination of the
403 attributes listed in \fBcurses\fP(3X).
404 The characters are passed to
405 the \fI\%putchar\fP-like function \fIputc\fP.
406 .PP
407 The \fBvidattr\fP routine is like the \fBvidputs\fP routine, except
408 that it outputs through \fI\%putchar\fP.
409 .PP
410 .B \%vid_attr
411 and
412 .B \%vid_puts
413 correspond to
414 .B \%vidattr
415 and
416 .BR \%vidputs ,
417 respectively.
418 They use multiple parameters to represent the character attributes and
419 color;
420 namely,
421 .bP
422 .I \%attrs,
423 of type
424 .I \%attr_t,
425 for the attributes and
426 .bP
427 .I pair,
428 of type
429 .I short,
430 for the color pair number.
431 .PP
432 Use the attribute constants prefixed with
433 .RB \*(`` WA_ \*(''
434 with
435 .B \%vid_attr
436 and
437 .BR \%vid_puts .
438 .PP
439 X/Open Curses reserves the
440 .I opts
441 argument for future use,
442 saying that applications must provide a null pointer for that argument;
443 but see section \*(``EXTENSIONS\*('' below.
444 .PP
445 The \fBmvcur\fP routine provides low-level cursor motion.
446 It takes effect immediately (rather than at the next refresh).
447 Unlike the other low-level output functions,
448 which either write to the standard output or pass an output function parameter,
449 \fBmvcur\fP uses an output file descriptor derived from
450 the output stream parameter of \fBnewterm\fP(3X).
451 .PP
452 While \fBputp\fP and \fBmvcur\fP are low-level functions which
453 do not use the high-level curses state,
454 they are declared in
455 .I \%curses.h
456 because System\ V did this
457 (see \fIHISTORY\fP).
458 .\" ***************************************************************************
459 .SS "Terminal Capability Functions"
460 The \fBtigetflag\fP, \fBtigetnum\fP and \fBtigetstr\fP routines return
461 the value of the capability corresponding to the
462 .I \%term\%info
463 \fIcapname\fP passed to them, such as \fBxenl\fP.
464 The \fIcapname\fP for each capability is given in the table column entitled
465 \fIcapname\fP code in the capabilities section of \fB\%terminfo\fP(5).
466 .PP
467 These routines return special values to denote errors.
468 .PP
469 The \fBtigetflag\fP routine returns
470 .TP
471 \fB\-1\fP
472 if \fIcapname\fP is not a Boolean capability,
473 or
474 .TP
475 \fB0\fP
476 if it is canceled or absent from the terminal description.
477 .PP
478 The \fBtigetnum\fP routine returns
479 .TP
480 \fB\-2\fP
481 if \fIcapname\fP is not a numeric capability, or
482 .TP
483 \fB\-1\fP
484 if it is canceled or absent from the terminal description.
485 .PP
486 The \fBtigetstr\fP routine returns
487 .TP
488 \fB(char *)\-1\fP
489 if \fIcapname\fP is not a string capability,
490 or
491 .TP
492 \fB0\fP
493 if it is canceled or absent from the terminal description.
494 .\" ***************************************************************************
495 .SS "Terminal Capability Names"
496 These null-terminated arrays contain
497 .bP
498 the short \fI\%term\%info\fP names (\*(``codes\*(''),
499 .bP
500 the \fItermcap\fP names (\*(``names\*(''), and
501 .bP
502 the long \fI\%term\%info\fP names (\*(``fnames\*('')
503 .PP
504 for each of the predefined
505 .I \%term\%info
506 variables:
507 .PP
508 .RS
509 .nf
510 \fBconst char *boolnames[]\fP, \fB*boolcodes[]\fP, \fB*boolfnames[]\fP
511 \fBconst char *numnames[]\fP, \fB*numcodes[]\fP, \fB*numfnames[]\fP
512 \fBconst char *strnames[]\fP, \fB*strcodes[]\fP, \fB*strfnames[]\fP
513 .fi
514 .RE
515 .\" ***************************************************************************
516 .SS "Releasing Memory"
517 Each successful call to \fBsetupterm\fP allocates memory to hold the terminal
518 description.
519 As a side-effect, it sets \fBcur_term\fP to point to this memory.
520 If an application calls
521 .IP
522 \fBdel_curterm(cur_term);\fP
523 .PP
524 the memory will be freed.
525 .PP
526 The formatting functions \fBtparm\fP and \fBtiparm\fP extend the storage
527 allocated by \fBsetupterm\fP:
528 .bP
529 the \*(``static\*('' terminfo variables [a-z].
530 Before \fI\%ncurses\fP 6.3, those were shared by all screens.
531 With \fI\%ncurses\fP 6.3, those are allocated per screen.
532 See \fB\%terminfo\fP(5) for details.
533 .bP
534 to improve performance,
535 \fI\%ncurses\fP 6.3 caches the result of analyzing terminfo
536 strings for their parameter types.
537 That is stored as a binary tree referenced from the \fI\%TERMINAL\fP structure.
538 .PP
539 The higher-level \fBinitscr\fP and \fBnewterm\fP functions use \fBsetupterm\fP.
540 Normally they do not free this memory, but it is possible to do that using
541 the \fBdelscreen\fP(3X) function.
542 .\" ***************************************************************************
543 .SH RETURN VALUE
544 X/Open defines no failure conditions.
545 In
546 .I \%ncurses,
547 .TP 5
548 \fBdel_curterm\fP
549 returns an error
550 if its terminal parameter is null.
551 .TP 5
552 \fBputp\fP
553 calls \fBtputs\fP, returning the same error-codes.
554 .TP 5
555 \fBrestartterm\fP
556 returns an error
557 if the associated call to \fBsetupterm\fP returns an error.
558 .TP 5
559 \fBsetupterm\fP
560 returns an error
561 if it cannot allocate enough memory, or
562 create the initial windows
563 .RB ( \%stdscr ,
564 .BR \%curscr ,
565 and
566 .BR \%newscr )
567 Other error conditions are documented above.
568 .TP 5
569 \fBtparm\fP
570 returns a null if the capability would require unexpected parameters,
571 e.g., too many, too few, or incorrect types
572 (strings where integers are expected, or vice versa).
573 .TP 5
574 \fBtputs\fP
575 returns an error if the string parameter is null.
576 It does not detect I/O errors:
577 X/Open Curses states that \fBtputs\fP ignores the return value
578 of the output function \fIputc\fP.
579 .\" ***************************************************************************
580 .SH NOTES
581 The
582 .B \%vid_attr
583 function in
584 .I \%ncurses
585 is a special case.
586 It was originally implemented based on a draft of X/Open Curses,
587 as a macro,
588 before other parts of the
589 .I \%ncurses
590 wide-character API were developed,
591 and unlike the other wide-character functions,
592 is also provided in the non-wide-character configuration.
593 .\" ***************************************************************************
594 .SH EXTENSIONS
595 The functions marked as extensions were designed for
596 .I \%ncurses,
597 and are not found in SVr4
598 .IR curses ,
599 4.4BSD
600 .IR curses ,
601 or any other previous curses implementation.
602 .PP
603 .I \%ncurses
604 allows
605 .I opts
606 to be a pointer to
607 .I int,
608 which overrides the
609 .I pair
610 .RI ( short )
611 argument.
612 .\" ***************************************************************************
613 .SH PORTABILITY
614 \fB\%setterm\fP is not described by X/Open and must be considered
615 non-portable.
616 All other functions are as described by X/Open.
617 .SS "Compatibility Macros"
618 This implementation provides a few macros for compatibility with systems
619 before SVr4
620 (see section \*(``HISTORY\*('' below).
621 They include
622 \fB\%Bcrmode\fP,
623 \fB\%Bfixterm\fP,
624 \fB\%Bgettmode\fP,
625 \fB\%Bnocrmode\fP,
626 \fB\%Bresetterm\fP,
627 \fB\%Bsaveterm\fP, and
628 \fB\%Bsetterm\fP.
629 .PP
630 In SVr4,
631 these are found in
632 .IR \%curses.h ,
633 but except for \fB\%setterm\fP,
634 are likewise macros.
635 The one function,
636 \fB\%setterm\fP,
637 is mentioned in the manual page.
638 It further notes that \fB\%setterm\fP was replaced by \fB\%setupterm\fP,
639 stating that the call
640 .RS
641 .EX
642 setupterm(\fIterm\fP, 1, (int *)0)
643 .EE
644 .RE
645 provides the same functionality as \fB\%setterm(\fIterm\fB)\fR,
646 discouraging the latter for new programs.
647 .I \%ncurses
648 implements each of these symbols as macros for BSD
649 .I curses
650 compatibility.
651 .SS "Legacy Data"
652 \fB\%setupterm\fP copies the terminal name to the array \fB\%ttytype\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,
660 as defined by
661 .RB \%\*(`` "@TIC@\ \-x" \*('',
662 are not stored in the arrays described here.
663 .SS "Output Buffering"
664 Older versions of \fI\%ncurses\fP assumed that the file descriptor
665 passed to \fB\%setupterm\fP from \fB\%initscr\fP or \fB\%newterm\fP uses
666 buffered I/O,
667 and would write to the corresponding stream.
668 In addition to the limitation that the terminal was left in
669 block-buffered mode on exit
670 (like System\ V
671 .IR curses ),
672 it was problematic because
673 .I \%ncurses
674 did not allow a reliable way to cleanup on receiving
675 .BR SIGTSTP .
676 .PP
677 The current version (ncurses6)
678 uses output buffers managed directly by
679 .I \%ncurses.
680 Some of the low-level functions described in this manual page write
681 to the standard output.
682 They are not signal-safe.
683 The high-level functions in
684 .I \%ncurses
685 employ alternate versions of these functions using the more reliable
686 buffering scheme.
687 .SS "Function Prototypes"
688 The X/Open Curses prototypes are based on the SVr4
689 .I curses
690 header declarations,
691 which were defined at the same time the C language was first
692 standardized in the late 1980s.
693 .bP
694 X/Open Curses uses
695 .I \%const
696 less effectively than a later design might,
697 in some cases applying it needlessly to values are already constant,
698 and in most cases overlooking parameters which normally would use
699 .I \%const.
700 Using constant parameters for functions which do not use
701 .I \%const
702 may prevent the program from compiling.
703 On the other hand,
704 \*(``writable strings\*('' are an obsolescent feature.
705 .IP
706 As an extension,
707 this implementation can be configured to change the function prototypes
708 to use the
709 .I \%const
710 keyword.
711 The
712 .I \%ncurses
713 ABI 6 enables this feature by default.
714 .bP
715 X/Open Curses prototypes \fB\%tparm\fP with a fixed number of
716 parameters,
717 rather than a variable argument list.
718 .IP
719 This implementation uses a variable argument list, but can be
720 configured to use the fixed-parameter list.
721 Portable applications should provide 9 parameters after the format;
722 zeroes are fine for this purpose.
723 .IP
724 In response to review comments by Thomas E. Dickey,
725 X/Open Curses Issue 7 proposed the \fB\%tiparm\fP function in mid-2009.
726 .IP
727 While \fB\%tiparm\fP is always provided in \fI\%ncurses\fP,
728 the older form is only available as a build-time configuration option.
729 If not specially configured,
730 \fB\%tparm\fP is the same as \fB\%tiparm\fP.
731 .PP
732 Both forms of \fB\%tparm\fP have drawbacks:
733 .bP
734 Most of the calls to \fB\%tparm\fP use only one or two parameters.
735 Passing nine on each call is awkward.
736 .IP
737 Using
738 .I long
739 for the numeric parameter type is a workaround to make the parameter use
740 the same amount of stack as a pointer.
741 That approach dates back to the mid-1980s, before C was standardized.
742 Since then, there is a standard
743 (and pointers are not required to fit in a long).
744 .bP
745 Providing the right number of parameters for a variadic function
746 such as \fB\%tiparm\fP can be a problem,
747 in particular for string parameters.
748 However, only a few terminfo capabilities use string parameters
749 (e.g., the ones used for programmable function keys).
750 .IP
751 The \fI\%ncurses\fP library checks usage of these capabilities,
752 and returns an error if the capability mishandles string parameters.
753 But it cannot check if a calling program provides strings in the right
754 places for the \fB\%tparm\fP calls.
755 .IP
756 The \fB\%@TPUT@\fR(1) program checks its use of these capabilities with
757 a table,
758 so that it calls \fB\%tparm\fP correctly.
759 .SS "Special \fITERM\fP treatment"
760 If configured to use the terminal-driver,
761 e.g., for the MinGW port,
762 .bP
763 \fB\%setupterm\fP interprets a missing/empty \fITERM\fP variable as the
764 special value \*(``unknown\*(''.
765 .IP
766 SVr4 curses uses the
767 special value \*(``dumb\*(''.
768 .IP
769 The difference between the two is that
770 the former uses the \fBgn\fP (\fB\%generic_type\fR) terminfo capability,
771 while the latter does not.
772 A generic terminal is unsuitable for full-screen applications.
773 .bP
774 \fB\%setupterm\fP allows explicit use of the
775 the windows console driver by checking if \fB$TERM\fP is set to
776 \*(``#win32con\*('' or an abbreviation of that string.
777 .SS "Other Portability Issues"
778 In SVr4,
779 \fB\%set_curterm\fP returns an
780 .I int,
781 .B OK
782 or
783 .BR ERR .
784 We have chosen to implement the X/Open Curses semantics.
785 .PP
786 In SVr4,
787 the third argument of \fB\%tputs\fP has the type
788 .RB \*(`` "int (*putc)(char)" \*(''.
789 .PP
790 At least one implementation of X/Open Curses (Solaris) returns a value
791 other than
792 .B OK
793 or
794 .B ERR
795 from \fB\%tputs\fP.
796 It instead returns the length of the string,
797 and does no error checking.
798 .PP
799 X/Open Curses notes that after calling \fB\%mvcur\fP,
800 the
801 .I curses
802 state may not match the actual terminal state,
803 and that an application should touch and refresh the window before
804 resuming normal
805 .I curses
806 calls.
807 Both
808 .I \%ncurses
809 and SVr4
810 .I curses
811 implement \fB\%mvcur\fP using the
812 .I SCREEN
813 data allocated in either \fB\%initscr\fP or \fB\%newterm\fP.
814 So though it is documented as a
815 .I \%term\%info
816 function,
817 \fB\%mvcur\fP is really a
818 .I curses
819 function that is not well specified.
820 .PP
821 X/Open notes that after calling \fBmvcur\fP, the curses state may not match the
822 actual terminal state, and that an application should touch and refresh
823 the window before resuming normal curses calls.
824 Both \fI\%ncurses\fP and System V Release 4 curses implement \fBmvcur\fP
825 using the \fISCREEN\fP data allocated in either \fBinitscr\fP or
826 \fBnewterm\fP.
827 So though it is documented as a terminfo function,
828 \fBmvcur\fP is really a curses function which is not well specified.
829 .PP
830 X/Open Curses states that the old location must be given for
831 \fB\%mvcur\fP to accommodate terminals that lack absolute cursor
832 positioning.
833 .\" X/Open Curses Issue 7, p. 161
834 .I \%ncurses
835 allows the caller to use \-1 for either or both old coordinates.
836 The \-1 tells
837 .I \%ncurses
838 that the old location is unknown,
839 and that it must use only absolute motion
840 (such as \fI\%cursor_address\fP)
841 rather than the least costly combination of absolute and relative motion.
842 .\" ***************************************************************************
843 .SH HISTORY
844 SVr2 (1984) introduced the
845 .I \%term\%info
846 feature.
847 Its programming manual mentioned the following low-level functions.
848 .PP
849 .TS
850 lB lB
851 lB lx.
852 Function        Description
853 _
854 fixterm restore tty to \*(``in curses\*('' state
855 gettmode        establish current tty modes
856 mvcur   low level cursor motion
857 putp    use \fBtputs\fP to send characters via \fI\%putchar\fP
858 resetterm       set tty modes to \*(``out of curses\*('' state
859 resetty reset tty flags to stored value
860 saveterm        save current modes as \*(``in curses\*('' state
861 savetty store current tty flags
862 setterm establish terminal with given type
863 setupterm       establish terminal with given type
864 tparm   interpolate parameters into string capability
865 tputs   apply padding information to a string
866 vidattr like \fBvidputs\fP, but output through \fIputchar\fP
867 vidputs write string to terminal, applying specified attributes
868 .TE
869 .PP
870 The programming manual also mentioned
871 functions provided for
872 .I termcap
873 compatibility
874 (commenting that they \*(``may go away at a later date\*('').
875 .PP
876 .TS
877 lB lB
878 lB lx.
879 Function        Description
880 _
881 tgetent look up \fItermcap\fP entry for given \fIname\fP
882 tgetflag        get Boolean entry for given \fIid\fP
883 tgetnum get numeric entry for given \fIid\fP
884 tgetstr get string entry for given \fIid\fP
885 tgoto   apply parameters to given capability
886 tputs   write characters via a function parameter, applying padding
887 .TE
888 .PP
889 Early
890 .I \%term\%info
891 programs obtained capability values from the
892 .I \%TERMINAL
893 structure initialized by \fB\%setupterm\fP.
894 .PP
895 SVr3 (1987) extended
896 .I \%term\%info
897 by adding functions to retrieve capability values
898 (like the
899 .I termcap
900 interface),
901 and reusing \fB\%tgoto\fP and \fB\%tputs\fP.
902 .PP
903 .TS
904 lB lB
905 lB lx.
906 Function        Description
907 _
908 tigetflag       get Boolean entry for given \fIid\fP
909 tigetnum        get numeric entry for given \fIid\fP
910 tigetstr        get string entry for given \fIid\fP
911 .TE
912 .PP
913 SVr3 also replaced several of the SVr2
914 .I \%term\%info
915 functions that had no counterpart in the
916 .I termcap
917 interface,
918 documenting them as obsolete.
919 .PP
920 .TS
921 lB lB
922 l  lx.
923 Function        Replaced by
924 _
925 crmode  cbreak
926 fixterm reset_prog_mode
927 gettmode        \fIn/a\fP
928 nocrmode        nocbreak
929 resetterm       reset_shell_mode
930 saveterm        def_prog_mode
931 setterm setupterm
932 .TE
933 .PP
934 SVr3 kept the \fB\%mvcur\fP,
935 \fB\%vidattr\fP,
936 and \fB\%vidputs\fP functions,
937 along with \fB\%putp\fP,
938 \fB\%tparm\fP,
939 and \fB\%tputs\fP.
940 The latter were needed to support padding,
941 and to handle capabilities accessed by functions such as \fB\%vidattr\fP
942 (which used more than the two parameters supported by \fB\%tgoto\fP).
943 .PP
944 SVr3 introduced the functions for switching between terminal
945 descriptions;
946 for example,
947 \fB\%set_curterm\fP.
948 Some changes reflected incremental improvements to the SVr2 library.
949 .bP
950 The
951 .I \%TERMINAL
952 type definition was introduced in SVr3.01,
953 for the
954 .I term
955 structure provided in SVr2.
956 .bP
957 Various global variables such as \fB\%boolnames\fP were mentioned
958 in the programming manual at this point,
959 though the variables had been provided in SVr2.
960 .PP
961 SVr4 (1989) added the \fB\%vid_attr\fP and \fB\%vid_puts\fP functions.
962 .PP
963 Other low-level functions are declared in the
964 .I curses
965 header files of Unix systems,
966 but none are documented.
967 Those noted as \*(``obsolete\*('' by SVr3 remained in use by System\ V's
968 \fIvi\fP(1) editor.
969 .SH SEE ALSO
970 \fB\%curses\fP(3X),
971 \fB\%curs_initscr\fP(3X),
972 \fB\%curs_kernel\fP(3X),
973 \fB\%curs_memleaks\fP(3X),
974 \fB\%curs_termcap\fP(3X),
975 \fB\%curs_variables\fP(3X),
976 \fB\%putc\fP(3),
977 \fB\%term_variables\fP(3X),
978 \fB\%terminfo\fP(5)