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