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