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