]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
ncurses 6.4 - patch 20230715
[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.71 2023/07/15 18:01:08 tom Exp $
32 .TH curs_util 3X 2023-07-15 "ncurses 6.4" "Library calls"
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 .SH DESCRIPTION
85 .SS unctrl
86 The \fBunctrl\fP routine returns a character string which is a printable
87 representation of the character \fIc\fP:
88 .bP
89 Printable characters are displayed as themselves,
90 e.g., a one-character string containing the key.
91 .bP
92 Control characters are displayed in the \fB^\fIX\fR notation.
93 .bP
94 Printing characters are displayed as is.
95 .bP
96 DEL (character 127) is displayed as \fB^?\fP.
97 .bP
98 Values above 128 are either meta characters
99 (if the screen has not been initialized,
100 or if \fBmeta\fP(3X) has been called with a \fBTRUE\fP parameter),
101 shown in the \fBM\-\fIX\fR notation,
102 or are displayed as themselves.
103 In the latter case, the values may not be printable;
104 this follows the X/Open specification.
105 .PP
106 The corresponding \fBwunctrl\fP returns a printable representation of
107 a complex character \fIc\fP.
108 .PP
109 In both \fBunctrl\fP and \fBwunctrl\fP the attributes and color associated
110 with the character parameter are ignored.
111 .SS keyname/key_name
112 The \fBkeyname\fP routine returns a character string
113 corresponding to the key \fIc\fP.
114 Key codes are different from character codes.
115 .bP
116 Key codes below 256 are characters.
117 They are displayed using \fBunctrl\fP.
118 .bP
119 Values above 256 may be the codes for function keys.
120 The function key name is displayed.
121 .bP
122 Otherwise (if there is no corresponding name and the key is not a character)
123 the function returns null, to denote an error.
124 X/Open also lists an \*(``UNKNOWN KEY\*('' return value,
125 which some implementations return rather than null.
126 .LP
127 The corresponding \fBkey_name\fP returns
128 a multibyte character string corresponding
129 to the wide-character value \fIw\fP.
130 The two functions (\fBkeyname\fP and \fBkey_name\fP)
131 do not return the same set of strings:
132 .bP
133 \fBkeyname\fP returns null where \fBkey_name\fP would display a meta character.
134 .bP
135 \fBkey_name\fP does not return the name of a function key.
136 .SS filter/nofilter
137 The \fBfilter\fP routine, if used, must be called before \fBinitscr\fP or
138 \fBnewterm\fP are called.
139 Calling \fBfilter\fP causes these changes in initialization:
140 .bP
141 \fBLINES\fP is set to 1;
142 .bP
143 the capabilities
144 \fBclear\fP,
145 \fBcud1\fP,
146 \fBcud\fP,
147 \fBcup\fP,
148 \fBcuu1\fP,
149 \fBcuu\fP,
150 \fBvpa\fP
151 are disabled;
152 .bP
153 the capability \fBed\fP is disabled if \fBbce\fP is set;
154 .bP
155 and the \fBhome\fP string is set to the value of \fBcr\fP.
156 .PP
157 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
158 call.
159 That allows the caller to initialize a screen on a different device,
160 using a different value of \fB$TERM\fP.
161 The limitation arises because the \fBfilter\fP routine modifies the
162 in-memory copy of the terminal information.
163 .SS use_env
164 The \fBuse_env\fP routine, if used,
165 should be called before \fBinitscr\fP or
166 \fBnewterm\fP are called
167 (because those compute the screen size).
168 It modifies the way \fBncurses\fP treats environment variables
169 when determining the screen size.
170 .bP
171 Normally \fBncurses\fP looks first at the terminal database for the screen size.
172 .IP
173 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
174 it stops here unless
175 \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
176 .bP
177 Then it asks for the screen size via operating system calls.
178 If successful,
179 it overrides the values from the terminal database.
180 .bP
181 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
182 \fBncurses\fP examines the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
183 using a value in those to override the results
184 from the operating system or terminal database.
185 .IP
186 \fBNcurses\fP also updates the screen size in response to \fBSIGWINCH\fP,
187 unless overridden by the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
188 .SS use_tioctl
189 The \fBuse_tioctl\fP routine, if used,
190 should be called before \fBinitscr\fP or \fBnewterm\fP are called
191 (because those compute the screen size).
192 After \fBuse_tioctl\fP is called with \fBTRUE\fP as an argument,
193 \fBncurses\fP modifies the last step in its computation
194 of screen size as follows:
195 .bP
196 checks if the \fBLINES\fP and \fBCOLUMNS\fP environment variables
197 are set to a number greater than zero.
198 .bP
199 for each, \fBncurses\fP updates the corresponding environment variable
200 with the value that it has obtained via operating system call
201 or from the terminal database.
202 .bP
203 \fBncurses\fP re-fetches the value of the environment variables so that
204 it is still the environment variables which set the screen size.
205 .PP
206 The \fBuse_env\fP and \fBuse_tioctl\fP routines combine as
207 summarized here:
208 .TS
209 center tab(/);
210 l l l
211 _ _ _
212 lw7 lw7 lw40.
213 \fBuse_env\fP/\fBuse_tioctl\fP/\fBSummary\fP
214 TRUE/FALSE/T{
215 This is the default behavior.
216 \fBncurses\fP uses operating system calls
217 unless overridden by $LINES or $COLUMNS environment variables.
218 T}
219 TRUE/TRUE/T{
220 \fBncurses\fP updates $LINES and $COLUMNS based on operating system calls.
221 T}
222 FALSE/TRUE/T{
223 \fBncurses\fP ignores $LINES and $COLUMNS,
224 uses operating system calls to obtain size.
225 T}
226 FALSE/FALSE/T{
227 \fBncurses\fP relies on the terminal database to determine size.
228 T}
229 .TE
230 .SS putwin/getwin
231 The \fBputwin\fP routine writes all data associated
232 with window (or pad) \fIwin\fP into
233 the file to which \fIfilep\fP points.
234 This information can be later retrieved
235 using the \fBgetwin\fP function.
236 .PP
237 The \fBgetwin\fP routine reads window related data stored in the file by
238 \fBputwin\fP.
239 The routine then creates and initializes a new window using that
240 data.
241 It returns a pointer to the new window.
242 There are a few caveats:
243 .bP
244 the data written is a copy of the \fBWINDOW\fP structure,
245 and its associated character cells.
246 The format differs between the wide-character (\fBncursesw\fP) and
247 non-wide (\fBncurses\fP) libraries.
248 You can transfer data between the two, however.
249 .bP
250 the retrieved window is always created as a top-level window (or pad),
251 rather than a subwindow.
252 .bP
253 the window's character cells contain the color pair \fIvalue\fP,
254 but not the actual color \fInumbers\fP.
255 If cells in the retrieved window use color pairs which have not been
256 created in the application using \fBinit_pair\fP,
257 they will not be colored when the window is refreshed.
258 .SS delay_output
259 The \fBdelay_output\fP routine inserts an \fIms\fP millisecond pause
260 in output.
261 This routine should not be used extensively because
262 padding characters are used rather than a CPU pause.
263 If no padding character is specified,
264 this uses \fBnapms\fP to perform the delay.
265 .SS flushinp
266 The \fBflushinp\fP routine throws away any typeahead that has been typed by the
267 user and has not yet been read by the program.
268 .SH RETURN VALUE
269 Except for \fBflushinp\fP, routines that return an integer return \fBERR\fP
270 upon failure and \fBOK\fP (SVr4 specifies only "an integer value other than
271 \fBERR\fP") upon successful completion.
272 .PP
273 Routines that return pointers return \fBNULL\fP on error.
274 .PP
275 X/Open does not define any error conditions.
276 In this implementation
277 .RS 3
278 .TP 5
279 \fBflushinp\fP
280 returns an error if the terminal was not initialized.
281 .TP 5
282 \fBputwin\fP
283 returns an error if the associated \fBfwrite\fP calls return an error.
284 .RE
285 .SH PORTABILITY
286 .SS filter
287 The SVr4 documentation describes the action of \fBfilter\fP only in the vaguest
288 terms.
289 The description here is adapted from the XSI Curses standard (which
290 erroneously fails to describe the disabling of \fBcuu\fP).
291 .SS keyname
292 The \fBkeyname\fP function may return the names of user-defined
293 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
294 option of \fB@TIC@\fP.
295 This implementation automatically assigns at run-time keycodes to
296 user-defined strings which begin with \*(``k\*(''.
297 The keycodes start at KEY_MAX, but are not guaranteed to be
298 the same value for different runs because user-defined codes are
299 merged from all terminal descriptions which have been loaded.
300 The \fBuse_extended_names\fP(3X) function controls whether this data is
301 loaded when the terminal description is read by the library.
302 .SS nofilter/use_tioctl
303 The \fBnofilter\fP and \fBuse_tioctl\fP routines are specific to \fBncurses\fP.
304 They were not supported on Version 7, BSD or System V implementations.
305 It is recommended that any code depending on \fBncurses\fP extensions
306 be conditioned using NCURSES_VERSION.
307 .SS putwin/getwin file-format
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 The XSI Curses standard, Issue 4 describes these functions.
339 It states that \fBunctrl\fP and \fBwunctrl\fP will return a null pointer if
340 unsuccessful, but does not define any error conditions.
341 This implementation checks for three cases:
342 .bP
343 the parameter is a 7-bit US\-ASCII code.
344 This is the case that X/Open Curses documented.
345 .bP
346 the parameter is in the range 128\-159, i.e., a C1 control code.
347 If \fBuse_legacy_coding\fP(3X) has been called with a \fB2\fP parameter,
348 \fBunctrl\fP returns the parameter, i.e., a one-character string with
349 the parameter as the first character.
350 Otherwise, it returns \*(``~@\*('', \*(``~A\*('', etc.,
351 analogous to \*(``^@\*('', \*(``^A\*('', C0 controls.
352 .IP
353 X/Open Curses does not document whether \fBunctrl\fP can be called before
354 initializing curses.
355 This implementation permits that,
356 and returns the \*(``~@\*('', etc., values in that case.
357 .bP
358 parameter values outside the 0 to 255 range.
359 \fBunctrl\fP returns a null pointer.
360 .PP
361 The strings returned by \fBunctrl\fP in this implementation are determined
362 at compile time,
363 showing C1 controls from the upper-128 codes
364 with a \*(``~\*('' prefix rather than \*(``^\*(''.
365 Other implementations have different conventions.
366 For example, they may show both sets of control characters with \*(``^\*('',
367 and strip the parameter to 7 bits.
368 Or they may ignore C1 controls and treat all of the upper-128 codes as
369 printable.
370 This implementation uses 8 bits but does not modify the string to reflect
371 locale.
372 The \fBuse_legacy_coding\fP(3X) function allows the caller to
373 change the output of \fBunctrl\fP.
374 .PP
375 Likewise, the \fBmeta\fP(3X) function allows the caller to change the
376 output of \fBkeyname\fP, i.e.,
377 it determines whether to use the \*(``M\-\*('' prefix
378 for \*(``meta\*('' keys (codes in the range 128 to 255).
379 Both \fBuse_legacy_coding\fP(3X) and \fBmeta\fP(3X) succeed only after
380 curses is initialized.
381 X/Open Curses does not document the treatment of codes 128 to 159.
382 When treating them as \*(``meta\*('' keys
383 (or if \fBkeyname\fP is called before initializing curses),
384 this implementation returns strings \*(``M\-^@\*('', \*(``M\-^A\*('', etc.
385 .PP
386 X/Open Curses documents \fBunctrl\fP as declared in \fB<unctrl.h>\fP,
387 which \fBncurses\fP does.
388 However, \fBncurses\fP' \fB<curses.h>\fP includes \fB<unctrl.h>\fP,
389 matching the behavior of SVr4 curses.
390 Other implementations may not do that.
391 .SS use_env/use_tioctl
392 If \fBncurses\fP is configured to provide the sp-functions extension,
393 the state of \fBuse_env\fP and \fBuse_tioctl\fP may be updated before
394 creating each \fIscreen\fP rather than once only
395 (\fBcurs_sp_funcs\fP(3X)).
396 This feature of \fBuse_env\fP
397 is not provided by other implementation of curses.
398 .SH SEE ALSO
399 \fBcurses\fP(3X),
400 \fBcurs_initscr\fP(3X),
401 \fBcurs_inopts\fP(3X),
402 \fBcurs_kernel\fP(3X),
403 \fBcurs_scr_dump\fP(3X),
404 \fBcurs_sp_funcs\fP(3X),
405 \fBcurs_variables\fP(3X),
406 \fBlegacy_coding\fP(3X).