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