1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
.\" $OpenBSD: terminfo.3,v 1.6 1999/07/09 13:35:28 aaron Exp $
.\"
.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 28, 1997
.Dt TERMINFO 3
.Os
.Sh NAME
.Nm setupterm ,
.Nm setterm ,
.Nm set_curterm ,
.Nm del_curterm ,
.Nm restartterm ,
.Nm tparm ,
.Nm tputs ,
.Nm putp ,
.Nm vidputs ,
.Nm vidattr ,
.Nm mvcur ,
.Nm tigetflag ,
.Nm tigetnum ,
.Nm tigetstr
.Nd interfaces to the terminfo database
.Sh SYNOPSIS
.Fd #include <term.h>
.Ft int
.Fn setupterm "const char *term" "int fildes" "int *errret"
.Ft int
.Fn setterm "const char *term"
.Ft TERMINAL *
.Fn set_curterm "TERMINAL *nterm"
.Ft int
.Fn del_curterm "TERMINAL *oterm"
.Ft int
.Fn restartterm "const char *term" "int fildes" "int *errret"
.Ft char *
.Fn tparm "const char *str" "..."
.Ft int
.Fn tputs "const char *str" "int affcnt" "int (*putc)(int))"
.Ft int
.Fn putp "const char *str"
.Ft int
.Fn vidputs "chtype attrs" "int (*putc)(char))"
.Ft int
.Fn vidattr "chtype attrs"
.Ft int
.Fn mvcur "int oldrow" "int oldcol" "int newrow" "int newcol"
.Ft int
.Fn tigetflag "const char *capname"
.Ft int
.Fn tigetnum "const char *capname"
.Ft char *
.Fn tigetstr "const char *capname"
.Sh DESCRIPTION
These low-level routines must be called by programs that have
to deal directly with the
.Nm terminfo
database to handle certain terminal capabilities, such as
programming function keys. For all other functionality,
.Xr curses 3
routines are more suitable and their use is recommended.
.Pp
Initially,
.Fn setupterm
should be called. Note that
.Fn setupterm
is automatically called by
.Fn initscr
and
.Fn newterm .
This defines the set of terminal-dependent variables [listed in
.Xr terminfo 5 ].
The
.Fn terminfo
variables
.Dv lines
and
.Dv columns
are initialized by
.Fn setupterm
as follows: If
.Fn use_env FALSE
has been called, values for
.Dv lines
and
.Dv columns
specified in
.Nm terminfo
are used. Otherwise, if the environment variables
.Ev LINES
and
.Ev COLUMNS
exist, their values are used. If these environment variables do not
exist and the program is running in a window, the current window size
is used. Otherwise, if the environment variables do not exist, the
values for
.Dv lines
and
.Dv columns
specified in the
.Nm terminfo
database are used.
.Pp
The header file
.Nm term.h
should be included to get the definitions for these strings, numbers,
and flags. Parameterized strings should be passed through
.Fn tparm
to instantiate them. All
.Nm terminfo
strings [including the output of
.Fn tparm ]
should be printed with
.Fn tputs
or
.Fn putp .
Call the
.Fn reset_shell_mode
function to restore the tty modes before exiting [see
.Xr curs_kernel 3 ].
Programs which use cursor addressing should output
.Nm enter_ca_mode
upon startup and should output
.Nm exit_ca_mode
before exiting. Programs desiring shell escapes should call
.Fn reset_shell_mode
and output
.Nm exit_ca_mode
before the shell is called and should output
.Nm enter_ca_mode
and call
.Fn reset_prog_mode
after returning from the shell.
.Pp
The
.Fn setupterm
routine reads in the
.Nm terminfo
database, initializing the
.Nm terminfo
structures, but does not set up the output virtualization structures
used by
.Xr curses 3 .
The terminal type is the character string
.Ar term ;
if
.Ar term
is null, the environment variable
.Ev TERM
is used. All output is to file descriptor
.Ar fildes
which is initialized for output. If
.Ar errret
is not null, then
.Fn setupterm
returns
.Dv OK
or
.Dv ERR
and stores a status value in the integer pointed to by
.Ar errret .
A status of
.Li 1
in
.Ar errret
is normal,
.Li 0
means that the terminal could not be found, and
.Li -1
means that the
.Nm terminfo
database could not be found. If
.Ar errret
is null,
.Fn setupterm
prints an error message upon finding an error and exits. Thus,
the simplest call is:
.Bd -literal -offset indent
setupterm((char *)0, 1, (int *)0);
.Ed
which uses all the defaults and sends the output to
.Dv stdout .
.Pp
The
.Fn setterm
routine is being replaced by
.Fn setupterm .
The call:
.Bd -literal -offset indent
setupterm(term, 1, (int *)0);
.Ed
provides the same functionality as:
.Bd -literal -offset indent
setterm(term);
.Ed
The
.Fn setterm
routine is included here for BSD compatibility, and is not recommended
for new programs.
.Pp
The
.Fn set_curterm
routine sets the variable
.Dv cur_term
to
.Ar nterm ,
and makes all of the
.Nm terminfo
boolean, numeric, and string variables use the values from
.Ar nterm .
It returns the old value of
.Dv cur_term .
.Pp
The
.Fn del_curterm
routine frees the space pointed to by
.Ar oterm
and makes it available for further use. If
.Ar oterm
is the same as
.Dv cur_term ,
references to any of the
.Nm terminfo
boolean, numeric, and string variables thereafter may refer to
invalid memory locations until another
.Fn setupterm
has been called.
.Pp
The
.Fn restartterm
routine is similar to
.Fn setupterm
and
.Fn initscr ,
except that it is called after restoring memory to a previous state (for
example, when reloading a game saved as a core image dump). It assumes that
the windows and the input and output options are the same as when memory was
saved, but the terminal type and baud rate may be different. Accordingly,
it saves various tty state bits, does a setupterm, and then restores the bits.
.Pp
The
.Fn tparm
routine instantiates the string
.Ar str ,
substituting the parameters %p1 through %p9
with the values of
.Ar p1
through
.Ar p9 .
A pointer is returned to the result of
.Ar str
with the parameters applied.
.Pp
The
.Fn tputs
routine applies padding information to the string
.Ar str
and outputs it. The
.Ar str
must be a terminfo string variable or the return value from
.Fn tparm ,
.Fn tgetstr ,
or
.Fn tgoto .
.Ar affcnt
is the number of lines affected, or 1 if not applicable.
.Ar putc
is a \fBputchar\fR-like routine to which the characters are
passed, one at a time.
.Pp
The
.Fn putp
routine calls:
.Bd -literal -offset indent
tputs(str, 1, putchar)
.Ed
Note that the output of
.Fn putp
always goes to
.Dv stdout ,
not to the
.Ar fildes
specified in
.Fn setupterm .
.Pp
The
.Fn vidputs
routine displays the string on the terminal in the video
attribute mode
.Ar attrs ,
which is any combination of the attributes listed in
.Xr curses 3 .
The characters are passed to the
\fBputchar\fR-like routine
.Ar putc .
.Pp
The
.Fn vidattr
routine is like the
.Fn vidputs
routine, except that it outputs through
.Fn putchar .
.Pp
The
.Fn mvcur
routine provides low-level cursor motion. It takes
effect immediately (rather than at the next refresh).
.Pp
The
.Fn tigetflag ,
.Fn tigetnum
and
.Fn tigetstr
routines return the value of the capability corresponding to the
.Fn terminfo
.Ar capname
passed to them, such as
.Dv xenl .
.Pp
The
.Fn tigetflag
routine returns the value
.Li -1
if
.Ar capname
is not a boolean capability.
.Pp
The
.Fn tigetnum
routine returns the value
.Li -2
if
.Ar capname
is not a numeric capability.
.Pp
The
.Fn tigetstr
routine returns the value
.Li (char *)-1
if
.Ar capname
is not a string capability.
.Pp
The
.Ar capname
for each capability is given in the table column entitled
.Ar capname
code in the capabilities section of
.Xr terminfo 5 .
.Pp
.\" XXX - finish converting these
\fBchar *boolnames\fR, \fB*boolcodes\fR, \fB*boolfnames\fR
.Pp
\fBchar *numnames\fR, \fB*numcodes\fR, \fB*numfnames\fR
.Pp
\fBchar *strnames\fR, \fB*strcodes\fR, \fB*strfnames\fR
.Pp
These null-terminated arrays contain the \fIcapnames\fR, the
\fBtermcap\fR codes, and the full C names, for each of the
\fBterminfo\fR variables.
.Sh RETURN VALUE
Routines that return an integer return
.Dv ERR
upon failure and
.Dv OK
(SVr4 only specifies
.Dq "an integer value other than ERR" )
upon successful completion, unless otherwise noted in the
preceding routine descriptions.
.Pp
Routines that return pointers always return
.Dv NULL
on error.
.Sh NOTES
The
.Fn setupterm
routine should be used in place of
.Fn setterm .
It may be useful when you want to test for terminal capabilities without
committing to the allocation of storage involved in
.Fn initscr .
.Pp
Note that
.Fn vidattr
and
.Fn vidputs
may be macros.
.Sh PORTABILITY
The function
.Fn setterm
is not described in the XSI Curses standard and must be considered
non-portable. All other functions are as described in the XSI curses standard.
.Pp
In System V Release 4,
.Fn set_curterm
has an
.Dv int
return type and returns
.Dv OK
or
.Dv ERR .
We have chosen to implement the XSI Curses semantics.
.Pp
In System V Release 4, the third argument of
.Fn tputs
has the type
\fBint (*putc)(char)\fR.
.Pp
The XSI Curses standard prototypes
.Fn tparm
with a fixed number of parameters, rather than a variable argument list.
.Sh SEE ALSO
.Xr curs_initscr 3 ,
.Xr curs_kernel 3 ,
.Xr curs_termcap 3 ,
.Xr curses 3 ,
.Xr putc 3 ,
.Xr terminfo 5
|