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