]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
ncurses 6.4 - patch 20230923
[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.83 2023/09/23 23:14:19 tom Exp $
32 .TH curs_util 3X 2023-09-23 "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 .SH NAME
42 \fB\%delay_output\fP,
43 \fB\%filter\fP,
44 \fB\%flushinp\fP,
45 \fB\%getwin\fP,
46 \fB\%key_name\fP,
47 \fB\%keyname\fP,
48 \fB\%nofilter\fP,
49 \fB\%putwin\fP,
50 \fB\%unctrl\fP,
51 \fB\%use_env\fP,
52 \fB\%use_tioctl\fP,
53 \fB\%wunctrl\fP \-
54 miscellaneous \fIcurses\fR utility routines
55 .SH SYNOPSIS
56 .nf
57 \fB#include <curses.h>\fP
58 .PP
59 \fBconst char *unctrl(chtype \fIc\fB);\fR
60 \fBwchar_t *wunctrl(cchar_t *\fIc\fB);\fR
61 .PP
62 \fBconst char *keyname(int \fIc\fB);\fR
63 \fBconst char *key_name(wchar_t \fIw\fB);\fR
64 .PP
65 \fBvoid filter(void);\fP
66 .PP
67 \fBvoid use_env(bool \fIf\fB);\fR
68 .PP
69 \fBint putwin(WINDOW *\fIwin\fB, FILE *\fIfilep\fB);\fR
70 \fBWINDOW *getwin(FILE *\fIfilep\fB);\fR
71 .PP
72 \fBint delay_output(int \fIms\fB);\fR
73 \fBint flushinp(void);\fP
74 .PP
75 \fI/* extensions */\fP
76 \fBvoid nofilter(void);\fP
77 \fBvoid use_tioctl(bool \fIf\fB);\fR
78 .fi
79 .SH DESCRIPTION
80 .SS unctrl
81 The \fBunctrl\fP routine returns a character string which is a printable
82 representation of the character \fIc\fP:
83 .bP
84 Printable characters are displayed as themselves,
85 e.g., a one-character string containing the key.
86 .bP
87 Control characters are displayed in the \fB^\fIX\fR notation.
88 .bP
89 Printing characters are displayed as is.
90 .bP
91 DEL (character 127) is displayed as \fB^?\fP.
92 .bP
93 Values above 128 are either meta characters
94 (if the screen has not been initialized,
95 or if \fBmeta\fP(3X) has been called with a \fBTRUE\fP parameter),
96 shown in the \fBM\-\fIX\fR notation,
97 or are displayed as themselves.
98 In the latter case, the values may not be printable;
99 this follows the X/Open specification.
100 .PP
101 The corresponding \fBwunctrl\fP returns a printable representation of
102 a complex character \fIc\fP.
103 .PP
104 In both \fBunctrl\fP and \fBwunctrl\fP the attributes and color associated
105 with the character parameter are ignored.
106 .SS keyname/key_name
107 The \fBkeyname\fP routine returns a character string
108 corresponding to the key \fIc\fP.
109 Key codes are different from character codes.
110 .bP
111 Key codes below 256 are characters.
112 They are displayed using \fBunctrl\fP.
113 .bP
114 Values above 256 may be the codes for function keys.
115 The function key name is displayed.
116 .bP
117 Otherwise (if there is no corresponding name and the key is not a character)
118 the function returns null, 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
123 a multibyte character string corresponding
124 to the wide-character value \fIw\fP.
125 The two functions (\fBkeyname\fP and \fBkey_name\fP)
126 do not return the same set of strings:
127 .bP
128 \fBkeyname\fP returns null where \fBkey_name\fP would display a meta character.
129 .bP
130 \fBkey_name\fP does not return the name of a function key.
131 .SS filter/nofilter
132 The \fBfilter\fP routine, if used, must be called before \fBinitscr\fP or
133 \fBnewterm\fP are called.
134 Calling \fBfilter\fP causes these changes in initialization:
135 .bP
136 \fBLINES\fP is set to 1;
137 .bP
138 the capabilities
139 \fBclear\fP,
140 \fBcud1\fP,
141 \fBcud\fP,
142 \fBcup\fP,
143 \fBcuu1\fP,
144 \fBcuu\fP,
145 \fBvpa\fP
146 are disabled;
147 .bP
148 the capability \fBed\fP is disabled if \fBbce\fP is set;
149 .bP
150 and the \fBhome\fP string is set to the value of \fBcr\fP.
151 .PP
152 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
153 call.
154 That allows the caller to initialize a screen on a different device,
155 using a different value of \fB$TERM\fP.
156 The limitation arises because the \fBfilter\fP routine modifies the
157 in-memory copy of the terminal information.
158 .SS use_env
159 The \fBuse_env\fP routine, if used,
160 should be called before \fBinitscr\fP or
161 \fBnewterm\fP are called
162 (because those compute the screen size).
163 It modifies the way \fIncurses\fP treats environment variables
164 when determining the screen size.
165 .bP
166 Normally \fIncurses\fP looks first at the terminal database for the screen size.
167 .IP
168 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
169 it stops here unless
170 \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
171 .bP
172 Then it asks for the screen size via operating system calls.
173 If successful,
174 it overrides the values from the terminal database.
175 .bP
176 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
177 \fBncurses\fP examines the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
178 using a value in those to override the results
179 from the operating system or terminal database.
180 .IP
181 \fBNcurses\fP also updates the screen size in response to \fBSIGWINCH\fP,
182 unless overridden by the \fBLINES\fP or \fBCOLUMNS\fP environment variables,
183 .SS use_tioctl
184 The \fBuse_tioctl\fP routine, if used,
185 should be called before \fBinitscr\fP or \fBnewterm\fP are called
186 (because those compute the screen size).
187 After \fBuse_tioctl\fP is called with \fBTRUE\fP as an argument,
188 \fBncurses\fP modifies the last step in its computation
189 of screen size as follows:
190 .bP
191 checks if the \fBLINES\fP and \fBCOLUMNS\fP environment variables
192 are set to a number greater than zero.
193 .bP
194 for each, \fBncurses\fP updates the corresponding environment variable
195 with the value that it has obtained via operating system call
196 or from the terminal database.
197 .bP
198 \fBncurses\fP re-fetches the value of the environment variables so that
199 it is still the environment variables which set the screen size.
200 .PP
201 The \fB\%use_env\fP and \fB\%use_tioctl\fP routines combine as follows.
202 .IP
203 .TS
204 lB lB lB
205 lB lB lx.
206 use_env use_tioctl      Summary
207 _
208 TRUE    FALSE   T{
209 This is the default behavior.
210 \fIncurses\fP uses operating system calls
211 unless overridden by \fBLINES\fP or \fB\%COLUMNS\fP environment
212 variables;
213 default.
214 T}
215 TRUE    TRUE    T{
216 \fIncurses\fP updates \fBLINES\fP and \fB\%COLUMNS\fP based on operating
217 system calls.
218 T}
219 FALSE   TRUE    T{
220 \fIncurses\fP ignores \fBLINES\fP and \fB\%COLUMNS\fP,
221 using operating system calls to obtain size.
222 T}
223 .TE
224 .SS putwin/getwin
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 The \fBdelay_output\fP routine inserts an \fIms\fP millisecond pause
254 in output.
255 This routine should not be used extensively because
256 padding characters are used rather than a CPU pause.
257 If no padding character is specified,
258 this uses \fBnapms\fP to perform the delay.
259 .SS flushinp
260 The \fBflushinp\fP routine throws away any typeahead that has been typed by the
261 user and has not yet been read by the program.
262 .SH RETURN VALUE
263 Except for \fBflushinp\fP, routines that return an integer return \fBERR\fP
264 upon failure and \fBOK\fP (SVr4 specifies only "an integer value other than
265 \fBERR\fP") upon successful completion.
266 .PP
267 Routines that return pointers return \fBNULL\fP on error.
268 .PP
269 X/Open does not define any error conditions.
270 In this implementation
271 .RS 3
272 .TP 5
273 \fBflushinp\fP
274 returns an error if the terminal was not initialized.
275 .TP 5
276 \fBputwin\fP
277 returns an error if the associated \fBfwrite\fP calls return an error.
278 .RE
279 .SH PORTABILITY
280 .SS filter
281 The SVr4 documentation describes the action of \fBfilter\fP only in the vaguest
282 terms.
283 The description here is adapted from the XSI Curses standard (which
284 erroneously fails to describe the disabling of \fBcuu\fP).
285 .SS keyname
286 The \fBkeyname\fP function may return the names of user-defined
287 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
288 option of \fB@TIC@\fP.
289 This implementation automatically assigns at run-time keycodes to
290 user-defined strings which begin with \*(``k\*(''.
291 The keycodes start at KEY_MAX, but are not guaranteed to be
292 the same value for different runs because user-defined codes are
293 merged from all terminal descriptions which have been loaded.
294 The \fBuse_extended_names\fP(3X) function controls whether this data is
295 loaded when the terminal description is read by the library.
296 .SS nofilter/use_tioctl
297 The \fBnofilter\fP and \fBuse_tioctl\fP routines are specific to \fBncurses\fP.
298 They were not supported on Version 7, BSD or System V implementations.
299 It is recommended that any code depending on \fBncurses\fP extensions
300 be conditioned using \fBNCURSES_VERSION\fP.
301 .SS putwin/getwin file-format
302 The \fBputwin\fP and \fBgetwin\fP functions have several issues with
303 portability:
304 .bP
305 The files written and read by these functions
306 use an implementation-specific format.
307 Although the format is an obvious target for standardization,
308 it has been overlooked.
309 .IP
310 Interestingly enough, according to the copyright dates in Solaris source,
311 the functions (along with \fBscr_init\fP, etc.) originated with
312 the University of California, Berkeley (in 1982)
313 and were later (in 1988) incorporated into SVr4.
314 Oddly, there are no such functions in the 4.3BSD curses sources.
315 .bP
316 Most implementations simply dump the binary \fBWINDOW\fP structure to the file.
317 These include SVr4 curses, NetBSD and PDCurses,
318 as well as older \fBncurses\fP versions.
319 This implementation
320 (as well as the X/Open variant of Solaris curses, dated 1995)
321 uses textual dumps.
322 .IP
323 The implementations which use binary dumps use block-I/O
324 (the \fBfwrite\fP and \fBfread\fP functions).
325 Those that use textual dumps use buffered-I/O.
326 A few applications may happen to write extra data in the file using
327 these functions.
328 Doing that can run into problems mixing block- and buffered-I/O.
329 This implementation reduces the problem on writes by flushing the output.
330 However, reading from a file written using mixed schemes may not be successful.
331 .SS unctrl/wunctrl
332 The XSI Curses standard, Issue 4 describes these functions.
333 It states that \fBunctrl\fP and \fBwunctrl\fP will return a null pointer if
334 unsuccessful, but does not define any error conditions.
335 This implementation checks for three cases:
336 .bP
337 the parameter is a 7-bit US\-ASCII code.
338 This is the case that X/Open Curses documented.
339 .bP
340 the parameter is in the range 128\-159, i.e., a C1 control code.
341 If \fBuse_legacy_coding\fP(3X) has been called with a \fB2\fP parameter,
342 \fBunctrl\fP returns the parameter, i.e., a one-character string with
343 the parameter as the first character.
344 Otherwise, it returns \*(``~@\*('', \*(``~A\*('', etc.,
345 analogous to \*(``^@\*('', \*(``^A\*('', C0 controls.
346 .IP
347 X/Open Curses does not document whether \fBunctrl\fP can be called before
348 initializing curses.
349 This implementation permits that,
350 and returns the \*(``~@\*('', etc., values in that case.
351 .bP
352 parameter values outside the 0 to 255 range.
353 \fBunctrl\fP returns a null pointer.
354 .PP
355 The strings returned by \fBunctrl\fP in this implementation are determined
356 at compile time,
357 showing C1 controls from the upper-128 codes
358 with a \*(``~\*('' prefix rather than \*(``^\*(''.
359 Other implementations have different conventions.
360 For example, they may show both sets of control characters with \*(``^\*('',
361 and strip the parameter to 7 bits.
362 Or they may ignore C1 controls and treat all of the upper-128 codes as
363 printable.
364 This implementation uses 8 bits but does not modify the string to reflect
365 locale.
366 The \fBuse_legacy_coding\fP(3X) function allows the caller to
367 change the output of \fBunctrl\fP.
368 .PP
369 Likewise, the \fBmeta\fP(3X) function allows the caller to change the
370 output of \fBkeyname\fP, i.e.,
371 it determines whether to use the \*(``M\-\*('' prefix
372 for \*(``meta\*('' keys (codes in the range 128 to 255).
373 Both \fBuse_legacy_coding\fP(3X) and \fBmeta\fP(3X) succeed only after
374 curses is initialized.
375 X/Open Curses does not document the treatment of codes 128 to 159.
376 When treating them as \*(``meta\*('' keys
377 (or if \fBkeyname\fP is called before initializing curses),
378 this implementation returns strings \*(``M\-^@\*('', \*(``M\-^A\*('', etc.
379 .PP
380 X/Open Curses documents \fBunctrl\fP as declared in \fB<unctrl.h>\fP,
381 which \fBncurses\fP does.
382 However, \fBncurses\fP' \fB<curses.h>\fP includes \fB<unctrl.h>\fP,
383 matching the behavior of SVr4 curses.
384 Other implementations may not do that.
385 .SS use_env/use_tioctl
386 If \fBncurses\fP is configured to provide the sp-functions extension,
387 the state of \fBuse_env\fP and \fBuse_tioctl\fP may be updated before
388 creating each \fIscreen\fP rather than once only
389 (\fBcurs_sp_funcs\fP(3X)).
390 This feature of \fBuse_env\fP
391 is not provided by other implementations of curses.
392 .SH SEE ALSO
393 \fBcurses\fP(3X),
394 \fBcurs_initscr\fP(3X),
395 \fBcurs_inopts\fP(3X),
396 \fBcurs_kernel\fP(3X),
397 \fBcurs_scr_dump\fP(3X),
398 \fBcurs_sp_funcs\fP(3X),
399 \fBcurs_variables\fP(3X),
400 \fBlegacy_coding\fP(3X).