summaryrefslogtreecommitdiff
path: root/lib/libtermlib/terminfo.3
blob: c8cd0233b3239fe29c1076ce88307db3b4ef1021 (plain)
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
446
447
448
449
450
451
452
453
454
455
.\" $OpenBSD: terminfo.3,v 1.1 1997/11/29 01:17:20 millert 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. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by Todd C. Miller.
.\" 4. 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 char *
.Fn tparam "const char *str" "char *buffer" "int size" "..."
.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,
.Nm setupterm
should be called.  Note that
.Nm setupterm
is automatically called by
.Nm initscr
and
.Nm newterm .
This defines the set of terminal-dependent variables [listed in
.Xr terminfo 5 ].
The
.Nm terminfo
variables
.Dv lines
and
.Dv columns
are initialized by
.Nm setupterm
as follows: If
.Nm 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
.Nm tparm
to instantiate them.  All
.Nm terminfo
strings [including the output of
.Nm tparm ]
should be printed with
.Nm tputs
or
.Nm putp .
Call the
.Nm 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
.Nm reset_shell_mode
and output
.Nm exit_ca_mode
before the shell is called and should output
.Nm enter_ca_mode
and call
.Nm reset_prog_mode
after returning from the shell.
.Pp
The
.Nm 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
.Dv term ;
if
.Dv term
is null, the environment variable
.Ev TERM
is used.  All output is to file descriptor
.Dv fildes
which is initialized for output.  If
.Dv errret
is not null, then
.Nm setupterm
returns
.Dv OK
or
.Dv ERR
and stores a status value in the integer pointed to by
.Dv errret .
A status of
.Li 1
in
.Dv 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
.Dv errret
is null,
.Nm 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
.Nm setterm
routine is being replaced by
.Nm 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
.Nm setterm
routine is included here for BSD compatibility, and is not recommended
for new programs.
.Pp
The
.Nm set_curterm
routine sets the variable
.Dv cur_term
to
.Dv nterm ,
and makes all of the
.Nm terminfo
boolean, numeric, and string variables use the values from
.Dv nterm .
It returns the old value of
.Dv cur_term .
.Pp
The
.Nm del_curterm
routine frees the space pointed to by
.Dv oterm
and makes it available for further use.  If
.Dv 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
.Nm setupterm
has been called.
.Pp
The
.Nm restartterm
routine is similar to
.Nm setupterm
and
.Nm 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
.Nm tparm
routine instantiates the string
.Dv str
with
parameters
.Dv pi .
A pointer is returned to the result of
.Dv str
with the parameters applied.
.Pp
The
.Nm tparam
routine is included for compatibility with the GNU termcap
implementation.  It works like
.Nm tparm
but you specify a buffer and buffer size to be filled with the expanded string.
.Pp
The
.Nm tputs
routine applies padding information to the string
.Dv str
and outputs it.  The
.Dv str
must be a terminfo string variable or the return value from
.Nm tparm ,
.Nm tgetstr ,
or
.Nm tgoto .
.Dv affcnt
is the number of lines affected, or 1 if not applicable.
.Dv putc
is a \fBputchar\fR-like routine to which the characters are
passed, one at a time.
.Pp
The
.Nm putp
routine calls:
.Bd -literal -offset indent
tputs(str, 1, putchar)

.Ed
Note that the output of
.Nm putp
always goes to
.Dv stdout ,
not to the
.Dv fildes
specified in
.Nm setupterm .
.Pp
The
.Nm vidputs
routine displays the string on the terminal in the video
attribute mode
.Dv attrs ,
which is any combination of the attributes listed in
.Xr curses 3 .
The characters are passed to the
\fBputchar\fR-like routine
.Dv putc .
.Pp
The
.Nm vidattr
routine is like the
.Nm vidputs
routine, except that it outputs through
.Nm putchar .
.Pp
The
.Nm mvcur
routine provides low-level cursor motion.  It takes
effect immediately (rather than at the next refresh).
.Pp
The
.Nm tigetflag ,
.Nm tigetnum
and
.Nm tigetstr
routines return the value of the capability corresponding to the
.Nm terminfo
.Dv capname
passed to them, such as
.Dv xenl .
.Pp
The
.Nm tigetflag
routine returns the value
.Li -1
if
.Dv capname
is not a boolean capability.
.Pp
The
.Nm tigetnum
routine returns the value
.Li -2
if
.Dv capname
is not a numeric capability.
.Pp
The
.Nm tigetstr
routine returns the value
.Li (char *)-1
if
.Dv capname
is not a string capability.
.Pp
The
.Dv capname
for each capability is given in the table column entitled
.Dv 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
.Nm setupterm
routine should be used in place of
.Nm setterm .
It may be useful when you want to test for terminal capabilities without
committing to the allocation of storage involved in
.Nm initscr .
.Pp
Note that
.Nm vidattr
and
.Nm vidputs
may be macros.
.Sh PORTABILITY
The function
.Nm 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,
.Nm 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
.Nm tputs
has the type
\fBint (*putc)(char)\fR.
.Pp
The XSI Curses standard prototypes
.Nm tparm
with a fixed number of parameters, rather than a variable argument list.
.Sh SEE ALSO
.Xr curses 3
.Xr curs_initscr 3 ,
.Xr curs_kernel 3 ,
.Xr curs_termcap 3 ,
.Xr putc 3 ,
.Xr terminfo 5