micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 1 | '\" t |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 2 | .\"*************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 3 | .\" Copyright 2018-2023,2024 Thomas E. Dickey * |
| 4 | .\" Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | .\" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 31 | .\" $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 Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 44 | .de bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 45 | .ie n .IP \(bu 4 |
| 46 | .el .IP \(bu 2 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 47 | .. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 48 | . |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 49 | .SH NAME |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 69 | .SH SYNOPSIS |
| 70 | .nf |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 71 | \fB#include <curses.h> |
| 72 | \fB#include <term.h> |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 73 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 117 | .fi |
| 118 | .SH DESCRIPTION |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 136 | .SS Initialization |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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). |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 144 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 145 | Applications can use the terminal capabilities either directly |
| 146 | (via header definitions), |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 147 | or by special functions. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 157 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 165 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 174 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 195 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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). |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 207 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 208 | Programs that use |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 209 | cursor addressing should |
| 210 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 211 | output \fB\%enter_ca_mode\fP upon startup and |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 212 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 213 | output \fB\%exit_ca_mode\fP before exiting. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 214 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 215 | Programs that execute shell subprocesses should |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 216 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 217 | call \fB\%reset_shell_mode\fP and |
| 218 | output \fB\%exit_ca_mode\fP before the shell |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 219 | is called and |
| 220 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 221 | output \fB\%enter_ca_mode\fP and |
| 222 | call \fB\%reset_prog_mode\fP after returning from the shell. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 223 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 | .IR 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 | .IR descriptor . |
| 254 | In |
| 255 | .IR 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 | .IR errret . |
| 271 | A return value of |
| 272 | .B OK |
| 273 | combined with status of |
| 274 | .B 1 |
| 275 | in |
| 276 | .I errret |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 277 | is normal. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 278 | .IP |
| 279 | If |
| 280 | .B ERR |
| 281 | is returned, |
| 282 | examine |
| 283 | .I errret: |
| 284 | .RS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 285 | .TP 5 |
| 286 | .B 1 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 287 | means that the terminal is hardcopy, |
| 288 | and cannot be used for |
| 289 | .I curses |
| 290 | applications. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 291 | .IP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 292 | \fB\%setupterm\fP determines if the entry is a hardcopy type by |
| 293 | checking the |
| 294 | .B \%hardcopy |
| 295 | .RB ( hc ) |
| 296 | capability. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 297 | .TP 5 |
| 298 | .B 0 |
| 299 | means that the terminal could not be found, |
| 300 | or that it is a generic type, |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 301 | having too little information for |
| 302 | .I curses |
| 303 | applications to run. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 304 | .IP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 310 | .TP 5 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 311 | .B \-1 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 339 | If it detects an error, |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 340 | or decides that the terminal is unsuitable |
| 341 | (hardcopy or generic), |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 342 | it discards this information, |
| 343 | making it not available to applications. |
| 344 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 345 | If \fB\%setupterm\fP is called repeatedly for the same terminal type, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 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, |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 349 | \fB\%setupterm\fP allocates new storage for each set of terminal |
| 350 | capabilities. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 351 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 352 | \fB\%set_curterm\fP sets \fB\%cur_term\fP to |
| 353 | .IR \%nterm , |
| 354 | and makes all of the |
| 355 | .I \%term\%info |
| 356 | Boolean, |
| 357 | numeric, |
| 358 | and string variables use the values from |
| 359 | .IR \%nterm . |
| 360 | It returns the old value of \fB\%cur_term\fP. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 361 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 375 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 382 | but the terminal type and baud rate may be different. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 | .IR pi . |
| 393 | A pointer is returned to the result of |
| 394 | .I str |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 395 | with the parameters applied. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 415 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 416 | \fB\%tiparm\fP is a newer form of \fB\%tparm\fP which uses |
| 417 | .I \%stdarg.h |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 418 | rather than a fixed-parameter list. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 419 | Its numeric parameters are |
| 420 | .IR int s |
| 421 | rather than |
| 422 | .IR long "s." |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 423 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 455 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 493 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 503 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 504 | \fB\%vidputs\fP displays the string on the terminal in the video |
| 505 | attribute mode |
| 506 | .IR 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 | .IR putc . |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 512 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 , |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 523 | respectively. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 524 | They use multiple parameters to represent the character attributes and |
| 525 | color; |
| 526 | namely, |
| 527 | .bP |
| 528 | .IR \%attrs , |
| 529 | of type |
| 530 | .IR \%attr_t , |
| 531 | for the attributes and |
| 532 | .bP |
| 533 | .IR pair , |
| 534 | of type |
| 535 | .IR short , |
| 536 | for the color pair number. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 537 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 538 | Use the attribute constants prefixed with |
| 539 | .RB \*(`` WA_ \*('' |
| 540 | with |
| 541 | .B \%vid_attr |
| 542 | and |
| 543 | .BR \%vid_puts . |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 544 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 550 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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). |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 559 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 | .IR 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 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 589 | .TP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 590 | .B \-1 |
| 591 | if |
| 592 | .I cap-code |
| 593 | is not a Boolean capability, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 594 | or |
| 595 | .TP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 596 | .B 0 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 597 | if it is canceled or absent from the terminal description. |
| 598 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 599 | \fB\%tigetnum\fP returns |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 600 | .TP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 601 | .B \-2 |
| 602 | if |
| 603 | .I cap-code |
| 604 | is not a numeric capability, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 605 | or |
| 606 | .TP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 607 | .B \-1 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 608 | if it is canceled or absent from the terminal description. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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" |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 622 | These null-terminated arrays contain |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 635 | .RS |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 641 | .RE |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 | .\" ******************************************************************** |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 686 | .SH RETURN VALUE |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 687 | X/Open Curses defines no failure conditions. |
| 688 | In |
| 689 | .IR \%ncurses , |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 690 | .TP 5 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 691 | .B del_curtem |
| 692 | fails if its terminal parameter is null. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 693 | .TP 5 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 694 | .B putp |
| 695 | calls \fB\%tputs\fP, |
| 696 | returning the same error codes. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 697 | .TP 5 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 698 | .B restartterm |
| 699 | fails if the associated call to \fB\%setupterm\fP returns an error. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 700 | .TP 5 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 ) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 708 | Other error conditions are documented above. |
| 709 | .TP 5 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 722 | It does not detect I/O errors: |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 | .IR \%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 | .IR int , |
| 756 | which overrides the |
| 757 | .I pair |
| 758 | .RI ( short ) |
| 759 | argument. |
| 760 | .\" ******************************************************************** |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 761 | .SH PORTABILITY |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 762 | \fB\%setterm\fP is not described by X/Open and must be considered |
| 763 | non-portable. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 764 | All other functions are as described by X/Open. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 778 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 804 | .PP |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 805 | Other implementions may not declare the capability name arrays. |
| 806 | Some provide them without declaring them. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 807 | X/Open Curses does not specify them. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 808 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 809 | Extended terminal capability names, |
| 810 | as defined by |
| 811 | .RB \%\*(`` "@TIC@ \-x" \*('', |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 812 | are not stored in the arrays described here. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 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 | .IR \%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 | sometimes applying it needlessly to values that are already constant, |
| 848 | and in most cases overlooking parameters that normally would use |
| 849 | .IR \%const . |
| 850 | Passing |
| 851 | .IR \%const -qualified |
| 852 | parameters to functions that do not declare them |
| 853 | .I \%const |
| 854 | may prevent the program from compiling. |
| 855 | On the other hand, |
| 856 | \*(``writable strings\*('' are an obsolescent feature. |
| 857 | .IP |
| 858 | As an extension, |
| 859 | this implementation can be configured to change the function prototypes |
| 860 | to use the |
| 861 | .I \%const |
| 862 | keyword. |
| 863 | The |
| 864 | .I \%ncurses |
| 865 | ABI 6 enables this feature by default. |
| 866 | .bP |
| 867 | X/Open Curses prototypes \fB\%tparm\fP with a fixed number of |
| 868 | parameters, |
| 869 | rather than a variable argument list. |
| 870 | .IP |
| 871 | This implementation uses a variable argument list, |
| 872 | but can be configured to use the fixed-parameter list. |
| 873 | Portable applications should provide nine parameters after the format; |
| 874 | zeroes are fine for this purpose. |
| 875 | .IP |
| 876 | In response to review comments by Thomas E. Dickey, |
| 877 | X/Open Curses Issue 7 proposed the \fB\%tiparm\fP function in mid-2009. |
| 878 | .IP |
| 879 | While \fB\%tiparm\fP is always provided in \fI\%ncurses\fP, |
| 880 | the older form is only available as a build-time configuration option. |
| 881 | If not specially configured, |
| 882 | \fB\%tparm\fP is the same as \fB\%tiparm\fP. |
| 883 | .PP |
| 884 | Both forms of \fB\%tparm\fP have drawbacks: |
| 885 | .bP |
| 886 | Most of the calls to \fB\%tparm\fP use only one or two parameters. |
| 887 | Passing nine on each call is awkward. |
| 888 | .IP |
| 889 | Using |
| 890 | .I long |
| 891 | for the numeric parameter type is a workaround to make the parameter use |
| 892 | the same amount of stack as a pointer. |
| 893 | That approach dates back to the mid-1980s, |
| 894 | before C was standardized. |
| 895 | Since then, |
| 896 | there is a standard |
| 897 | (and pointers are not required to fit in a |
| 898 | .IR long ). |
| 899 | .bP |
| 900 | Providing the right number of parameters for a variadic function |
| 901 | such as \fB\%tiparm\fP can be a problem, |
| 902 | in particular for string parameters. |
| 903 | However, |
| 904 | only a few |
| 905 | .I \%term\%info |
| 906 | capabilities use string parameters |
| 907 | (for instance, |
| 908 | the ones used for programmable function keys). |
| 909 | .IP |
| 910 | The \fI\%ncurses\fP library checks usage of these capabilities, |
| 911 | and returns an error if the capability mishandles string parameters. |
| 912 | But it cannot check if a calling program provides strings in the right |
| 913 | places for the \fB\%tparm\fP calls. |
| 914 | .IP |
| 915 | The \fB\%@TPUT@\fR(1) program checks its use of these capabilities with |
| 916 | a table, |
| 917 | so that it calls \fB\%tparm\fP correctly. |
| 918 | .SS "Special \fITERM\fP treatment" |
| 919 | If configured to use the terminal driver, |
| 920 | .\" XXX: as opposed to the Unix terminal driver, termio(s)? |
| 921 | as with the MinGW port, |
| 922 | .bP |
| 923 | \fB\%setupterm\fP interprets a missing/empty \fITERM\fP variable as the |
| 924 | special value \*(``unknown\*(''. |
| 925 | .IP |
| 926 | SVr4 |
| 927 | .I curses |
| 928 | uses the special value \*(``dumb\*(''. |
| 929 | .IP |
| 930 | The difference between the two is that the former uses the |
| 931 | .B \%generic_type |
| 932 | .RB ( gn ) |
| 933 | .I \%term\%info |
| 934 | capability, |
| 935 | while the latter does not. |
| 936 | A generic terminal is unsuitable for full-screen applications. |
| 937 | .bP |
| 938 | \fB\%setupterm\fP allows explicit use of the |
| 939 | the 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" |
| 942 | In SVr4, |
| 943 | \fB\%set_curterm\fP returns an |
| 944 | .IR int , |
| 945 | .B OK |
| 946 | or |
| 947 | .BR ERR . |
| 948 | We have chosen to implement the X/Open Curses semantics. |
| 949 | .PP |
| 950 | In SVr4, |
| 951 | the third argument of \fB\%tputs\fP has the type |
| 952 | .RB \*(`` "int (*putc)(char)" \*(''. |
| 953 | .PP |
| 954 | At least one implementation of X/Open Curses (Solaris) returns a value |
| 955 | other than |
| 956 | .B OK |
| 957 | or |
| 958 | .B ERR |
| 959 | from \fB\%tputs\fP. |
| 960 | It instead returns the length of the string, |
| 961 | and does no error checking. |
| 962 | .PP |
| 963 | X/Open Curses notes that after calling \fB\%mvcur\fP, |
| 964 | the |
| 965 | .I curses |
| 966 | state may not match the actual terminal state, |
| 967 | and that an application should touch and refresh the window before |
| 968 | resuming normal |
| 969 | .I curses |
| 970 | calls. |
| 971 | Both |
| 972 | .I \%ncurses |
| 973 | and SVr4 |
| 974 | .I curses |
| 975 | implement \fB\%mvcur\fP using the |
| 976 | .I SCREEN |
| 977 | data allocated in either \fB\%initscr\fP or \fB\%newterm\fP. |
| 978 | So though it is documented as a |
| 979 | .I \%term\%info |
| 980 | function, |
| 981 | \fB\%mvcur\fP is really a |
| 982 | .I curses |
| 983 | function that is not well specified. |
| 984 | .PP |
| 985 | X/Open Curses states that the old location must be given for |
| 986 | \fB\%mvcur\fP to accommodate terminals that lack absolute cursor |
| 987 | positioning. |
| 988 | .\" X/Open Curses Issue 7, p. 161 |
| 989 | .I \%ncurses |
| 990 | allows the caller to use \-1 for either or both old coordinates. |
| 991 | The \-1 tells |
| 992 | .I \%ncurses |
| 993 | that the old location is unknown, |
| 994 | and that it must use only absolute motion, |
| 995 | as with the |
| 996 | .B \%cursor_address |
| 997 | .RB ( cup ) |
| 998 | capability, |
| 999 | rather than the least costly combination of absolute and relative |
| 1000 | motion. |
| 1001 | .\" ******************************************************************** |
| 1002 | .SH HISTORY |
| 1003 | SVr2 (1984) introduced the |
| 1004 | .I \%term\%info |
| 1005 | feature. |
| 1006 | Its programming manual mentioned the following low-level functions. |
| 1007 | .PP |
| 1008 | .TS |
| 1009 | lB lB |
| 1010 | lB lx. |
| 1011 | Function Description |
| 1012 | _ |
| 1013 | fixterm restore terminal to \*(``in \fIcurses\fP\*('' state |
| 1014 | gettmode establish current terminal modes |
| 1015 | mvcur low level cursor motion |
| 1016 | putp use \fBtputs\fP to send characters via \fIputchar\fP |
| 1017 | resetterm set terminal modes to \*(``out of \fIcurses\fP\*(''\ |
| 1018 | state |
| 1019 | resetty reset terminal flags to stored value |
| 1020 | saveterm save current modes as \*(``in \fIcurses\fP\*('' state |
| 1021 | savetty store current terminal flags |
| 1022 | setterm establish terminal with given type |
| 1023 | setupterm establish terminal with given type |
| 1024 | tparm interpolate parameters into string capability |
| 1025 | tputs apply padding information to a string |
| 1026 | vidattr like \fBvidputs\fP, but output through \fIputchar\fP |
| 1027 | vidputs T{ |
| 1028 | write string to terminal, applying specified attributes |
| 1029 | T} |
| 1030 | .TE |
| 1031 | .PP |
| 1032 | The programming manual also mentioned |
| 1033 | functions provided for |
| 1034 | .I termcap |
| 1035 | compatibility |
| 1036 | (commenting that they \*(``may go away at a later date\*(''). |
| 1037 | .PP |
| 1038 | .TS |
| 1039 | lB lB |
| 1040 | lB lx. |
| 1041 | Function Description |
| 1042 | _ |
| 1043 | tgetent look up \fItermcap\fP entry for given \fIname\fP |
| 1044 | tgetflag get Boolean entry for given \fIid\fP |
| 1045 | tgetnum get numeric entry for given \fIid\fP |
| 1046 | tgetstr get string entry for given \fIid\fP |
| 1047 | tgoto apply parameters to given capability |
| 1048 | tputs T{ |
| 1049 | write characters via a function parameter, applying padding |
| 1050 | T} |
| 1051 | .TE |
| 1052 | .PP |
| 1053 | Early |
| 1054 | .I \%term\%info |
| 1055 | programs obtained capability values from the |
| 1056 | .I \%TERMINAL |
| 1057 | structure initialized by \fB\%setupterm\fP. |
| 1058 | .PP |
| 1059 | SVr3 (1987) extended |
| 1060 | .I \%term\%info |
| 1061 | by adding functions to retrieve capability values |
| 1062 | (like the |
| 1063 | .I termcap |
| 1064 | interface), |
| 1065 | and reusing \fB\%tgoto\fP and \fB\%tputs\fP. |
| 1066 | .PP |
| 1067 | .TS |
| 1068 | lB lB |
| 1069 | lB lx. |
| 1070 | Function Description |
| 1071 | _ |
| 1072 | tigetflag get Boolean entry for given \fIid\fP |
| 1073 | tigetnum get numeric entry for given \fIid\fP |
| 1074 | tigetstr get string entry for given \fIid\fP |
| 1075 | .TE |
| 1076 | .PP |
| 1077 | SVr3 also replaced several of the SVr2 |
| 1078 | .I \%term\%info |
| 1079 | functions that had no counterpart in the |
| 1080 | .I termcap |
| 1081 | interface, |
| 1082 | documenting them as obsolete. |
| 1083 | .PP |
| 1084 | .TS |
| 1085 | lB lB |
| 1086 | l lx. |
| 1087 | Function Replaced by |
| 1088 | _ |
| 1089 | crmode cbreak |
| 1090 | fixterm reset_prog_mode |
| 1091 | gettmode \fIn/a\fP |
| 1092 | nocrmode nocbreak |
| 1093 | resetterm reset_shell_mode |
| 1094 | saveterm def_prog_mode |
| 1095 | setterm setupterm |
| 1096 | .TE |
| 1097 | .PP |
| 1098 | SVr3 kept the \fB\%mvcur\fP, |
| 1099 | \fB\%vidattr\fP, |
| 1100 | and \fB\%vidputs\fP functions, |
| 1101 | along with \fB\%putp\fP, |
| 1102 | \fB\%tparm\fP, |
| 1103 | and \fB\%tputs\fP. |
| 1104 | The latter were needed to support padding, |
| 1105 | and 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 |
| 1108 | SVr3 introduced the functions for switching between terminal |
| 1109 | descriptions; |
| 1110 | for example, |
| 1111 | \fB\%set_curterm\fP. |
| 1112 | Some changes reflected incremental improvements to the SVr2 library. |
| 1113 | .bP |
| 1114 | The |
| 1115 | .I \%TERMINAL |
| 1116 | type definition was introduced in SVr3.01, |
| 1117 | for the |
| 1118 | .I term |
| 1119 | structure provided in SVr2. |
| 1120 | .bP |
| 1121 | Various global variables such as \fB\%boolnames\fP were mentioned |
| 1122 | in the programming manual at this point, |
| 1123 | though the variables had been provided in SVr2. |
| 1124 | .PP |
| 1125 | SVr4 (1989) added the \fB\%vid_attr\fP and \fB\%vid_puts\fP functions. |
| 1126 | .PP |
| 1127 | Other low-level functions are declared in the |
| 1128 | .I curses |
| 1129 | header files of Unix systems, |
| 1130 | but none are documented. |
| 1131 | Those noted as \*(``obsolete\*('' by SVr3 remained in use by System\ V's |
| 1132 | \fIvi\fP(1) editor. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1133 | .SH SEE ALSO |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 1134 | \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) |