]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
ncurses 6.4 - patch 20230311
[ncurses.git] / man / curs_util.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2022,2023 Thomas E. Dickey                                *
4 .\" Copyright 1998-2015,2017 Free Software Foundation, Inc.                  *
5 .\"                                                                          *
6 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
7 .\" copy of this software and associated documentation files (the            *
8 .\" "Software"), to deal in the Software without restriction, including      *
9 .\" without limitation the rights to use, copy, modify, merge, publish,      *
10 .\" distribute, distribute with modifications, sublicense, and/or sell       *
11 .\" copies of the Software, and to permit persons to whom the Software is    *
12 .\" furnished to do so, subject to the following conditions:                 *
13 .\"                                                                          *
14 .\" The above copyright notice and this permission notice shall be included  *
15 .\" in all copies or substantial portions of the Software.                   *
16 .\"                                                                          *
17 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24 .\"                                                                          *
25 .\" Except as contained in this notice, the name(s) of the above copyright   *
26 .\" holders shall not be used in advertising or otherwise to promote the     *
27 .\" sale, use or other dealings in this Software without prior written       *
28 .\" authorization.                                                           *
29 .\"***************************************************************************
30 .\"
31 .\" $Id: curs_util.3x,v 1.66 2023/03/11 20:28:02 tom Exp $
32 .TH curs_util 3X ""
33 .ie \n(.g .ds `` \(lq
34 .el       .ds `` ``
35 .ie \n(.g .ds '' \(rq
36 .el       .ds '' ''
37 .de bP
38 .ie n  .IP \(bu 4
39 .el    .IP \(bu 2
40 ..
41 .na
42 .hy 0
43 .SH NAME
44 \fBdelay_output\fP,
45 \fBfilter\fP,
46 \fBflushinp\fP,
47 \fBgetwin\fP,
48 \fBkey_name\fP,
49 \fBkeyname\fP,
50 \fBnofilter\fP,
51 \fBputwin\fP,
52 \fBunctrl\fP,
53 \fBuse_env\fP,
54 \fBuse_tioctl\fP,
55 \fBwunctrl\fP \- miscellaneous \fBcurses\fP utility routines
56 .ad
57 .hy
58 .SH SYNOPSIS
59 \fB#include <curses.h>\fP
60 .sp
61 \fBconst char *unctrl(chtype \fIc\fB);\fR
62 .br
63 \fBwchar_t *wunctrl(cchar_t *\fIc\fB);\fR
64 .sp
65 \fBconst char *keyname(int \fIc\fB);\fR
66 .br
67 \fBconst char *key_name(wchar_t \fIw\fB);\fR
68 .sp
69 \fBvoid filter(void);\fP
70 .br
71 \fBvoid nofilter(void);\fP
72 .sp
73 \fBvoid use_env(bool \fIf\fB);\fR
74 .br
75 \fBvoid use_tioctl(bool \fIf\fB);\fR
76 .sp
77 \fBint putwin(WINDOW *\fIwin\fB, FILE *\fIfilep\fB);\fR
78 .br
79 \fBWINDOW *getwin(FILE *\fIfilep\fB);\fR
80 .sp
81 \fBint delay_output(int \fIms\fB);\fR
82 .br
83 \fBint flushinp(void);\fP
84 .br
85 .SH DESCRIPTION
86 .SS unctrl
87 .PP
88 The \fBunctrl\fP routine returns a character string which is a printable
89 representation of the character \fIc\fP, ignoring attributes.
90 Control characters are displayed in the \fB^\fIX\fR notation.
91 Printing characters are displayed as is.
92 .PP
93 The corresponding \fBwunctrl\fP returns a printable representation of
94 a wide character.
95 .SS keyname/key_name
96 .PP
97 The \fBkeyname\fP routine returns a character string
98 corresponding to the key \fIc\fP:
99 .bP
100 Printable characters are displayed as themselves,
101 e.g., a one-character string containing the key.
102 .bP
103 Control characters are displayed in the \fB^\fIX\fR notation.
104 .bP
105 DEL (character 127) is displayed as \fB^?\fP.
106 .bP
107 Values above 128 are either meta characters
108 (if the screen has not been initialized,
109 or if \fBmeta\fP(3X) has been called with a \fBTRUE\fP parameter),
110 shown in the \fBM\-\fIX\fR notation,
111 or are displayed as themselves.
112 In the latter case, the values may not be printable;
113 this follows the X/Open specification.
114 .bP
115 Values above 256 may be the names of the names of function keys.
116 .bP
117 Otherwise (if there is no corresponding name) the function returns null,
118 to denote an error.
119 X/Open also lists an \*(``UNKNOWN KEY\*('' return value,
120 which some implementations return rather than null.
121 .LP
122 The corresponding \fBkey_name\fP returns a character string corresponding
123 to the wide-character value \fIw\fP.
124 The two functions do not return the same set of strings;
125 the latter returns null where the former would display a meta character.
126 .SS filter/nofilter
127 .PP
128 The \fBfilter\fP routine, if used, must be called before \fBinitscr\fP or
129 \fBnewterm\fP are called.
130 Calling \fBfilter\fP causes these changes in initialization:
131 .bP
132 \fBLINES\fP is set to 1;
133 .bP
134 the capabilities
135 \fBclear\fP,
136 \fBcud1\fP,
137 \fBcud\fP,
138 \fBcup\fP,
139 \fBcuu1\fP,
140 \fBcuu\fP,
141 \fBvpa\fP
142 are disabled;
143 .bP
144 the capability \fBed\fP is disabled if \fBbce\fP is set;
145 .bP
146 and the \fBhome\fP string is set to the value of \fBcr\fP.
147 .PP
148 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
149 call.
150 That allows the caller to initialize a screen on a different device,
151 using a different value of \fB$TERM\fP.
152 The limitation arises because the \fBfilter\fP routine modifies the
153 in-memory copy of the terminal information.
154 .SS use_env
155 .PP
156 The \fBuse_env\fP routine, if used,
157 should be called before \fBinitscr\fP or
158 \fBnewterm\fP are called
159 (because those compute the screen size).
160 It modifies the way \fBncurses\fP treats environment variables
161 when determining the screen size.
162 .bP
163 Normally \fBncurses\fP looks first at the terminal database for the screen size.
164 .IP
165 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
166 it stops here unless
167 \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
168 .bP
169 Then it asks for the screen size via operating system calls.
170 If successful,
171 it overrides the values from the terminal database.
172 .bP
173 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
174 \fBncurses\fP examines the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
175 using a value in those to override the results
176 from the operating system or terminal database.
177 .IP
178 \fBNcurses\fP also updates the screen size in response to \fBSIGWINCH\fP,
179 unless overridden by the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
180 .SS use_tioctl
181 .PP
182 The \fBuse_tioctl\fP routine, if used,
183 should be called before \fBinitscr\fP or \fBnewterm\fP are called
184 (because those compute the screen size).
185 After \fBuse_tioctl\fP is called with \fBTRUE\fP as an argument,
186 \fBncurses\fP modifies the last step in its computation
187 of screen size as follows:
188 .bP
189 checks if the \fBLINES\fP and \fBCOLUMNS\fP environment variables
190 are set to a number greater than zero.
191 .bP
192 for each, \fBncurses\fP updates the corresponding environment variable
193 with the value that it has obtained via operating system call
194 or from the terminal database.
195 .bP
196 \fBncurses\fP re-fetches the value of the environment variables so that
197 it is still the environment variables which set the screen size.
198 .PP
199 The \fBuse_env\fP and \fBuse_tioctl\fP routines combine as
200 summarized here:
201 .TS
202 center tab(/);
203 l l l
204 _ _ _
205 lw7 lw7 lw40.
206 \fBuse_env\fP/\fBuse_tioctl\fP/\fBSummary\fP
207 TRUE/FALSE/T{
208 This is the default behavior.
209 \fBncurses\fP uses operating system calls
210 unless overridden by $LINES or $COLUMNS environment variables.
211 T}
212 TRUE/TRUE/T{
213 \fBncurses\fP updates $LINES and $COLUMNS based on operating system calls.
214 T}
215 FALSE/TRUE/T{
216 \fBncurses\fP ignores $LINES and $COLUMNS,
217 uses operating system calls to obtain size.
218 T}
219 FALSE/FALSE/T{
220 \fBncurses\fP relies on the terminal database to determine size.
221 T}
222 .TE
223 .SS putwin/getwin
224 .PP
225 The \fBputwin\fP routine writes all data associated
226 with window (or pad) \fIwin\fP into
227 the file to which \fIfilep\fP points.
228 This information can be later retrieved
229 using the \fBgetwin\fP function.
230 .PP
231 The \fBgetwin\fP routine reads window related data stored in the file by
232 \fBputwin\fP.
233 The routine then creates and initializes a new window using that
234 data.
235 It returns a pointer to the new window.
236 There are a few caveats:
237 .bP
238 the data written is a copy of the \fBWINDOW\fP structure,
239 and its associated character cells.
240 The format differs between the wide-character (\fBncursesw\fP) and
241 non-wide (\fBncurses\fP) libraries.
242 You can transfer data between the two, however.
243 .bP
244 the retrieved window is always created as a top-level window (or pad),
245 rather than a subwindow.
246 .bP
247 the window's character cells contain the color pair \fIvalue\fP,
248 but not the actual color \fInumbers\fP.
249 If cells in the retrieved window use color pairs which have not been
250 created in the application using \fBinit_pair\fP,
251 they will not be colored when the window is refreshed.
252 .SS delay_output
253 .PP
254 The \fBdelay_output\fP routine inserts an \fIms\fP millisecond pause
255 in output.
256 This routine should not be used extensively because
257 padding characters are used rather than a CPU pause.
258 If no padding character is specified,
259 this uses \fBnapms\fP to perform the delay.
260 .SS flushinp
261 .PP
262 The \fBflushinp\fP routine throws away any typeahead that has been typed by the
263 user and has not yet been read by the program.
264 .SH RETURN VALUE
265 Except for \fBflushinp\fP, routines that return an integer return \fBERR\fP
266 upon failure and \fBOK\fP (SVr4 specifies only "an integer value other than
267 \fBERR\fP") upon successful completion.
268 .PP
269 Routines that return pointers return \fBNULL\fP on error.
270 .PP
271 X/Open does not define any error conditions.
272 In this implementation
273 .RS 3
274 .TP 5
275 \fBflushinp\fP
276 returns an error if the terminal was not initialized.
277 .TP 5
278 \fBputwin\fP
279 returns an error if the associated \fBfwrite\fP calls return an error.
280 .RE
281 .SH PORTABILITY
282 .SS filter
283 .PP
284 The SVr4 documentation describes the action of \fBfilter\fP only in the vaguest
285 terms.
286 The description here is adapted from the XSI Curses standard (which
287 erroneously fails to describe the disabling of \fBcuu\fP).
288 .SS keyname
289 .PP
290 The \fBkeyname\fP function may return the names of user-defined
291 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
292 option of \fB@TIC@\fP.
293 This implementation automatically assigns at run-time keycodes to
294 user-defined strings which begin with \*(``k\*(''.
295 The keycodes start at KEY_MAX, but are not guaranteed to be
296 the same value for different runs because user-defined codes are
297 merged from all terminal descriptions which have been loaded.
298 The \fBuse_extended_names\fP(3X) function controls whether this data is
299 loaded when the terminal description is read by the library.
300 .SS nofilter/use_tioctl
301 .PP
302 The \fBnofilter\fP and \fBuse_tioctl\fP routines are specific to \fBncurses\fP.
303 They were not supported on Version 7, BSD or System V implementations.
304 It is recommended that any code depending on \fBncurses\fP extensions
305 be conditioned using NCURSES_VERSION.
306 .SS putwin/getwin file-format
307 .PP
308 The \fBputwin\fP and \fBgetwin\fP functions have several issues with
309 portability:
310 .bP
311 The files written and read by these functions
312 use an implementation-specific format.
313 Although the format is an obvious target for standardization,
314 it has been overlooked.
315 .IP
316 Interestingly enough, according to the copyright dates in Solaris source,
317 the functions (along with \fBscr_init\fP, etc.) originated with
318 the University of California, Berkeley (in 1982)
319 and were later (in 1988) incorporated into SVr4.
320 Oddly, there are no such functions in the 4.3BSD curses sources.
321 .bP
322 Most implementations simply dump the binary \fBWINDOW\fP structure to the file.
323 These include SVr4 curses, NetBSD and PDCurses,
324 as well as older \fBncurses\fP versions.
325 This implementation
326 (as well as the X/Open variant of Solaris curses, dated 1995)
327 uses textual dumps.
328 .IP
329 The implementations which use binary dumps use block-I/O
330 (the \fBfwrite\fP and \fBfread\fP functions).
331 Those that use textual dumps use buffered-I/O.
332 A few applications may happen to write extra data in the file using
333 these functions.
334 Doing that can run into problems mixing block- and buffered-I/O.
335 This implementation reduces the problem on writes by flushing the output.
336 However, reading from a file written using mixed schemes may not be successful.
337 .SS unctrl/wunctrl
338 .PP
339 The XSI Curses standard, Issue 4 describes these functions.
340 It states that \fBunctrl\fP and \fBwunctrl\fP will return a null pointer if
341 unsuccessful, but does not define any error conditions.
342 This implementation checks for three cases:
343 .bP
344 the parameter is a 7-bit US\-ASCII code.
345 This is the case that X/Open Curses documented.
346 .bP
347 the parameter is in the range 128\-159, i.e., a C1 control code.
348 If \fBuse_legacy_coding\fP(3X) has been called with a \fB2\fP parameter,
349 \fBunctrl\fP returns the parameter, i.e., a one-character string with
350 the parameter as the first character.
351 Otherwise, it returns \*(``~@\*('', \*(``~A\*('', etc.,
352 analogous to \*(``^@\*('', \*(``^A\*('', C0 controls.
353 .IP
354 X/Open Curses does not document whether \fBunctrl\fP can be called before
355 initializing curses.
356 This implementation permits that,
357 and returns the \*(``~@\*('', etc., values in that case.
358 .bP
359 parameter values outside the 0 to 255 range.
360 \fBunctrl\fP returns a null pointer.
361 .PP
362 The strings returned by \fBunctrl\fP in this implementation are determined
363 at compile time,
364 showing C1 controls from the upper-128 codes
365 with a \*(``~\*('' prefix rather than \*(``^\*(''.
366 Other implementations have different conventions.
367 For example, they may show both sets of control characters with \*(``^\*('',
368 and strip the parameter to 7 bits.
369 Or they may ignore C1 controls and treat all of the upper-128 codes as
370 printable.
371 This implementation uses 8 bits but does not modify the string to reflect
372 locale.
373 The \fBuse_legacy_coding\fP(3X) function allows the caller to
374 change the output of \fBunctrl\fP.
375 .PP
376 Likewise, the \fBmeta\fP(3X) function allows the caller to change the
377 output of \fBkeyname\fP, i.e.,
378 it determines whether to use the \*(``M\-\*('' prefix
379 for \*(``meta\*('' keys (codes in the range 128 to 255).
380 Both \fBuse_legacy_coding\fP(3X) and \fBmeta\fP(3X) succeed only after
381 curses is initialized.
382 X/Open Curses does not document the treatment of codes 128 to 159.
383 When treating them as \*(``meta\*('' keys
384 (or if \fBkeyname\fP is called before initializing curses),
385 this implementation returns strings \*(``M\-^@\*('', \*(``M\-^A\*('', etc.
386 .PP
387 X/Open Curses documents \fBunctrl\fP as declared in \fB<unctrl.h>\fP,
388 which \fBncurses\fP does.
389 However, \fBncurses\fP' \fB<curses.h>\fP includes \fB<unctrl.h>\fP,
390 matching the behavior of SVr4 curses.
391 Other implementations may not do that.
392 .SS use_env/use_tioctl
393 .PP
394 If \fBncurses\fP is configured to provide the sp-functions extension,
395 the state of \fBuse_env\fP and \fBuse_tioctl\fP may be updated before
396 creating each \fIscreen\fP rather than once only
397 (\fBcurs_sp_funcs\fP(3X)).
398 This feature of \fBuse_env\fP
399 is not provided by other implementation of curses.
400 .SH SEE ALSO
401 \fBcurses\fP(3X),
402 \fBcurs_initscr\fP(3X),
403 \fBcurs_inopts\fP(3X),
404 \fBcurs_kernel\fP(3X),
405 \fBcurs_scr_dump\fP(3X),
406 \fBcurs_sp_funcs\fP(3X),
407 \fBcurs_variables\fP(3X),
408 \fBlegacy_coding\fP(3X).