]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
ncurses 6.4 - patch 20231007
[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.86 2023/10/07 21:19:07 tom Exp $
32 .TH curs_util 3X 2023-10-07 "ncurses 6.4" "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 .
44 .de bP
45 .ie n  .IP \(bu 4
46 .el    .IP \(bu 2
47 ..
48 .SH NAME
49 \fB\%delay_output\fP,
50 \fB\%filter\fP,
51 \fB\%flushinp\fP,
52 \fB\%getwin\fP,
53 \fB\%key_name\fP,
54 \fB\%keyname\fP,
55 \fB\%nofilter\fP,
56 \fB\%putwin\fP,
57 \fB\%unctrl\fP,
58 \fB\%use_env\fP,
59 \fB\%use_tioctl\fP,
60 \fB\%wunctrl\fP \-
61 miscellaneous \fIcurses\fR utility routines
62 .SH SYNOPSIS
63 .nf
64 \fB#include <curses.h>
65 .PP
66 \fBconst char *unctrl(chtype \fIc\fP);
67 \fBwchar_t *wunctrl(cchar_t *\fIc\fP);
68 .PP
69 \fBconst char *keyname(int \fIc\fP);
70 \fBconst char *key_name(wchar_t \fIw\fP);
71 .PP
72 \fBvoid filter(void);
73 .PP
74 \fBvoid use_env(bool \fIf\fP);
75 .PP
76 \fBint putwin(WINDOW *\fIwin\fP, FILE *\fIfilep\fP);
77 \fBWINDOW *getwin(FILE *\fIfilep\fP);
78 .PP
79 \fBint delay_output(int \fIms\fP);
80 \fBint flushinp(void);
81 .PP
82 \fI/* extensions */
83 \fBvoid nofilter(void);
84 \fBvoid use_tioctl(bool \fIf\fP);
85 .fi
86 .SH DESCRIPTION
87 .SS unctrl
88 The \fBunctrl\fP routine returns a character string which is a printable
89 representation of the character \fIc\fP:
90 .bP
91 Printable characters are displayed as themselves,
92 e.g., a one-character string containing the key.
93 .bP
94 Control characters are displayed in the \fB^\fIX\fR notation.
95 .bP
96 Printing characters are displayed as is.
97 .bP
98 DEL (character 127) is displayed as \fB^?\fP.
99 .bP
100 Values above 128 are either meta characters
101 (if the screen has not been initialized,
102 or if \fBmeta\fP(3X) has been called with a \fBTRUE\fP parameter),
103 shown in the \fBM\-\fIX\fR notation,
104 or are displayed as themselves.
105 In the latter case, the values may not be printable;
106 this follows the X/Open specification.
107 .PP
108 The corresponding \fBwunctrl\fP returns a printable representation of
109 a complex character \fIc\fP.
110 .PP
111 In both \fBunctrl\fP and \fBwunctrl\fP the attributes and color associated
112 with the character parameter are ignored.
113 .SS keyname/key_name
114 The \fBkeyname\fP routine returns a character string
115 corresponding to the key \fIc\fP.
116 Key codes are different from character codes.
117 .bP
118 Key codes below 256 are characters.
119 They are displayed using \fBunctrl\fP.
120 .bP
121 Values above 256 may be the codes for function keys.
122 The function key name is displayed.
123 .bP
124 Otherwise (if there is no corresponding name and the key is not a character)
125 the function returns null, to denote an error.
126 X/Open also lists an \*(``UNKNOWN KEY\*('' return value,
127 which some implementations return rather than null.
128 .LP
129 The corresponding \fBkey_name\fP returns
130 a multibyte character string corresponding
131 to the wide-character value \fIw\fP.
132 The two functions (\fBkeyname\fP and \fBkey_name\fP)
133 do not return the same set of strings:
134 .bP
135 \fBkeyname\fP returns null where \fBkey_name\fP would display a meta character.
136 .bP
137 \fBkey_name\fP does not return the name of a function key.
138 .SS filter/nofilter
139 The \fBfilter\fP routine, if used, must be called before \fBinitscr\fP or
140 \fBnewterm\fP are called.
141 Calling \fBfilter\fP causes these changes in initialization:
142 .bP
143 \fBLINES\fP is set to 1;
144 .bP
145 the capabilities
146 \fBclear\fP,
147 \fBcud1\fP,
148 \fBcud\fP,
149 \fBcup\fP,
150 \fBcuu1\fP,
151 \fBcuu\fP,
152 \fBvpa\fP
153 are disabled;
154 .bP
155 the capability \fBed\fP is disabled if \fBbce\fP is set;
156 .bP
157 and the \fBhome\fP string is set to the value of \fBcr\fP.
158 .PP
159 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
160 call.
161 That allows the caller to initialize a screen on a different device,
162 using a different value of \fB$TERM\fP.
163 The limitation arises because the \fBfilter\fP routine modifies the
164 in-memory copy of the terminal information.
165 .SS use_env
166 The \fBuse_env\fP routine, if used,
167 should be called before \fBinitscr\fP or
168 \fBnewterm\fP are called
169 (because those compute the screen size).
170 It modifies the way \fIncurses\fP treats environment variables
171 when determining the screen size.
172 .bP
173 Normally \fIncurses\fP looks first at the terminal database for the screen size.
174 .IP
175 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
176 it stops here unless
177 \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
178 .bP
179 Then it asks for the screen size via operating system calls.
180 If successful,
181 it overrides the values from the terminal database.
182 .bP
183 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
184 \fBncurses\fP examines the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
185 using a value in those to override the results
186 from the operating system or terminal database.
187 .IP
188 \fBNcurses\fP also updates the screen size in response to \fBSIGWINCH\fP,
189 unless overridden by the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
190 .SS use_tioctl
191 The \fBuse_tioctl\fP routine, if used,
192 should be called before \fBinitscr\fP or \fBnewterm\fP are called
193 (because those compute the screen size).
194 After \fBuse_tioctl\fP is called with \fBTRUE\fP as an argument,
195 \fBncurses\fP modifies the last step in its computation
196 of screen size as follows:
197 .bP
198 checks if the \fBLINES\fP and \fBCOLUMNS\fP environment variables
199 are set to a number greater than zero.
200 .bP
201 for each, \fBncurses\fP updates the corresponding environment variable
202 with the value that it has obtained via operating system call
203 or from the terminal database.
204 .bP
205 \fBncurses\fP re-fetches the value of the environment variables so that
206 it is still the environment variables which set the screen size.
207 .PP
208 The \fB\%use_env\fP and \fB\%use_tioctl\fP routines combine as follows.
209 .IP
210 .TS
211 lB lB lB
212 lB lB lx.
213 use_env use_tioctl      Summary
214 _
215 TRUE    FALSE   T{
216 This is the default behavior.
217 \fIncurses\fP uses operating system calls
218 unless overridden by \fBLINES\fP or \fB\%COLUMNS\fP environment
219 variables;
220 default.
221 T}
222 TRUE    TRUE    T{
223 \fIncurses\fP updates \fBLINES\fP and \fB\%COLUMNS\fP based on operating
224 system calls.
225 T}
226 FALSE   TRUE    T{
227 \fIncurses\fP ignores \fBLINES\fP and \fB\%COLUMNS\fP,
228 using operating system calls to obtain size.
229 T}
230 .TE
231 .SS putwin/getwin
232 The \fBputwin\fP routine writes all data associated
233 with window (or pad) \fIwin\fP into
234 the file to which \fIfilep\fP points.
235 This information can be later retrieved
236 using the \fBgetwin\fP function.
237 .PP
238 The \fBgetwin\fP routine reads window related data stored in the file by
239 \fBputwin\fP.
240 The routine then creates and initializes a new window using that
241 data.
242 It returns a pointer to the new window.
243 There are a few caveats:
244 .bP
245 the data written is a copy of the \fBWINDOW\fP structure,
246 and its associated character cells.
247 The format differs between the wide-character (\fBncursesw\fP) and
248 non-wide (\fBncurses\fP) libraries.
249 You can transfer data between the two, however.
250 .bP
251 the retrieved window is always created as a top-level window (or pad),
252 rather than a subwindow.
253 .bP
254 the window's character cells contain the color pair \fIvalue\fP,
255 but not the actual color \fInumbers\fP.
256 If cells in the retrieved window use color pairs which have not been
257 created in the application using \fBinit_pair\fP,
258 they will not be colored when the window is refreshed.
259 .SS delay_output
260 The \fBdelay_output\fP routine inserts an \fIms\fP millisecond pause
261 in output.
262 This routine should not be used extensively because
263 padding characters are used rather than a CPU pause.
264 If no padding character is specified,
265 this uses \fBnapms\fP to perform the delay.
266 .SS flushinp
267 The \fBflushinp\fP routine throws away any typeahead that has been typed by the
268 user and has not yet been read by the program.
269 .SH RETURN VALUE
270 Except for \fBflushinp\fP, routines that return an integer return \fBERR\fP
271 upon failure and \fBOK\fP (SVr4 specifies only "an integer value other than
272 \fBERR\fP") upon successful completion.
273 .PP
274 Routines that return pointers return \fBNULL\fP on error.
275 .PP
276 X/Open does not define any error conditions.
277 In this implementation
278 .RS 3
279 .TP 5
280 \fBflushinp\fP
281 returns an error if the terminal was not initialized.
282 .TP 5
283 \fBputwin\fP
284 returns an error if the associated \fBfwrite\fP calls return an error.
285 .RE
286 .SH PORTABILITY
287 .SS filter
288 The SVr4 documentation describes the action of \fBfilter\fP only in the vaguest
289 terms.
290 The description here is adapted from the XSI Curses standard (which
291 erroneously fails to describe the disabling of \fBcuu\fP).
292 .SS keyname
293 The \fBkeyname\fP function may return the names of user-defined
294 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
295 option of \fB@TIC@\fP.
296 This implementation automatically assigns at run-time keycodes to
297 user-defined strings which begin with \*(``k\*(''.
298 The keycodes start at KEY_MAX, but are not guaranteed to be
299 the same value for different runs because user-defined codes are
300 merged from all terminal descriptions which have been loaded.
301 The \fBuse_extended_names\fP(3X) function controls whether this data is
302 loaded when the terminal description is read by the library.
303 .SS nofilter/use_tioctl
304 The \fBnofilter\fP and \fBuse_tioctl\fP routines are specific to \fBncurses\fP.
305 They were not supported on Version 7, BSD or System V implementations.
306 It is recommended that any code depending on \fBncurses\fP extensions
307 be conditioned using \fBNCURSES_VERSION\fP.
308 .SS putwin/getwin file-format
309 The \fBputwin\fP and \fBgetwin\fP functions have several issues with
310 portability:
311 .bP
312 The files written and read by these functions
313 use an implementation-specific format.
314 Although the format is an obvious target for standardization,
315 it has been overlooked.
316 .IP
317 Interestingly enough, according to the copyright dates in Solaris source,
318 the functions (along with \fBscr_init\fP, etc.) originated with
319 the University of California, Berkeley (in 1982)
320 and were later (in 1988) incorporated into SVr4.
321 Oddly, there are no such functions in the 4.3BSD curses sources.
322 .bP
323 Most implementations simply dump the binary \fBWINDOW\fP structure to the file.
324 These include SVr4 curses, NetBSD and PDCurses,
325 as well as older \fBncurses\fP versions.
326 This implementation
327 (as well as the X/Open variant of Solaris curses, dated 1995)
328 uses textual dumps.
329 .IP
330 The implementations which use binary dumps use block-I/O
331 (the \fBfwrite\fP and \fBfread\fP functions).
332 Those that use textual dumps use buffered-I/O.
333 A few applications may happen to write extra data in the file using
334 these functions.
335 Doing that can run into problems mixing block- and buffered-I/O.
336 This implementation reduces the problem on writes by flushing the output.
337 However, reading from a file written using mixed schemes may not be successful.
338 .SS unctrl/wunctrl
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 If \fBncurses\fP is configured to provide the sp-functions extension,
394 the state of \fBuse_env\fP and \fBuse_tioctl\fP may be updated before
395 creating each \fIscreen\fP rather than once only
396 (\fBcurs_sp_funcs\fP(3X)).
397 This feature of \fBuse_env\fP
398 is not provided by other implementations of curses.
399 .SH SEE ALSO
400 \fB\%curses\fP(3X),
401 \fB\%curs_initscr\fP(3X),
402 \fB\%curs_inopts\fP(3X),
403 \fB\%curs_kernel\fP(3X),
404 \fB\%curs_scr_dump\fP(3X),
405 \fB\%curs_sp_funcs\fP(3X),
406 \fB\%curs_variables\fP(3X),
407 \fB\%legacy_coding\fP(3X)