]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
ncurses 6.1 - patch 20200111
[ncurses.git] / man / curs_util.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_util.3x,v 1.56 2019/11/30 21:04:02 tom Exp $
31 .TH curs_util 3X ""
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de bP
37 .ie n  .IP \(bu 4
38 .el    .IP \(bu 2
39 ..
40 .na
41 .hy 0
42 .SH NAME
43 \fBdelay_output\fR,
44 \fBfilter\fR,
45 \fBflushinp\fR,
46 \fBgetwin\fR,
47 \fBkey_name\fR,
48 \fBkeyname\fR,
49 \fBnofilter\fR,
50 \fBputwin\fR,
51 \fBunctrl\fR,
52 \fBuse_env\fR,
53 \fBuse_tioctl\fR,
54 \fBwunctrl\fR \- miscellaneous \fBcurses\fR utility routines
55 .ad
56 .hy
57 .SH SYNOPSIS
58 \fB#include <curses.h>\fR
59 .sp
60 \fBconst char *unctrl(chtype c);\fR
61 .br
62 \fBwchar_t *wunctrl(cchar_t *c);\fR
63 .br
64 \fBconst char *keyname(int c);\fR
65 .br
66 \fBconst char *key_name(wchar_t w);\fR
67 .br
68 \fBvoid filter(void);\fR
69 .br
70 \fBvoid nofilter(void);\fR
71 .br
72 \fBvoid use_env(bool f);\fR
73 .br
74 \fBvoid use_tioctl(bool f);\fR
75 .br
76 \fBint putwin(WINDOW *win, FILE *filep);\fR
77 .br
78 \fBWINDOW *getwin(FILE *filep);\fR
79 .br
80 \fBint delay_output(int ms);\fR
81 .br
82 \fBint flushinp(void);\fR
83 .br
84 .SH DESCRIPTION
85 .SS unctrl
86 .PP
87 The \fBunctrl\fR routine returns a character string which is a printable
88 representation of the character \fIc\fR, ignoring attributes.
89 Control characters are displayed in the \fB^\fR\fIX\fR notation.
90 Printing characters are displayed as is.
91 The corresponding \fBwunctrl\fR returns a printable representation of
92 a wide character.
93 .SS keyname/key_name
94 .PP
95 The \fBkeyname\fR routine returns a character string
96 corresponding to the key \fIc\fR:
97 .bP
98 Printable characters are displayed as themselves,
99 e.g., a one-character string containing the key.
100 .bP
101 Control characters are displayed in the \fB^\fR\fIX\fR notation.
102 .bP
103 DEL (character 127) is displayed as \fB^?\fP.
104 .bP
105 Values above 128 are either meta characters
106 (if the screen has not been initialized,
107 or if \fBmeta\fP(3X) has been called with a \fBTRUE\fP parameter),
108 shown in the \fBM\-\fR\fIX\fR notation,
109 or are displayed as themselves.
110 In the latter case, the values may not be printable;
111 this follows the X/Open specification.
112 .bP
113 Values above 256 may be the names of the names of function keys.
114 .bP
115 Otherwise (if there is no corresponding name) the function returns null,
116 to denote an error.
117 X/Open also lists an \*(``UNKNOWN KEY\*('' return value,
118 which some implementations return rather than null.
119 .LP
120 The corresponding \fBkey_name\fR returns a character string corresponding
121 to the wide-character value \fIw\fR.
122 The two functions do not return the same set of strings;
123 the latter returns null where the former would display a meta character.
124 .SS filter/nofilter
125 .PP
126 The \fBfilter\fR routine, if used, must be called before \fBinitscr\fR or
127 \fBnewterm\fR are called.
128 Calling \fBfilter\fP causes these changes in initialization:
129 .bP
130 \fBLINES\fR is set to 1;
131 .bP
132 the capabilities
133 \fBclear\fR,
134 \fBcud1\fR,
135 \fBcud\fR,
136 \fBcup\fR,
137 \fBcuu1\fR,
138 \fBcuu\fR,
139 \fBvpa\fR
140 are disabled;
141 .bP
142 the capability \fBed\fP is disabled if \fBbce\fP is set;
143 .bP
144 and the \fBhome\fR string is set to the value of \fBcr\fR.
145 .PP
146 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
147 call.
148 That allows the caller to initialize a screen on a different device,
149 using a different value of \fB$TERM\fP.
150 The limitation arises because the \fBfilter\fP routine modifies the
151 in-memory copy of the terminal information.
152 .SS use_env
153 .PP
154 The \fBuse_env\fR routine, if used,
155 should be called before \fBinitscr\fR or
156 \fBnewterm\fR are called
157 (because those compute the screen size).
158 It modifies the way \fBncurses\fP treats environment variables
159 when determining the screen size.
160 .bP
161 Normally \fBncurses\fP looks first at the terminal database for the screen size.
162 .IP
163 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
164 it stops here unless
165 \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
166 .bP
167 Then it asks for the screen size via operating system calls.
168 If successful,
169 it overrides the values from the terminal database.
170 .bP
171 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
172 \fBncurses\fP examines the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
173 using a value in those to override the results
174 from the operating system or terminal database.
175 .IP
176 \fBNcurses\fP also updates the screen size in response to \fBSIGWINCH\fP,
177 unless overridden by the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
178 .SS use_tioctl
179 .PP
180 The \fBuse_tioctl\fR routine, if used,
181 should be called before \fBinitscr\fR or \fBnewterm\fR are called
182 (because those compute the screen size).
183 After \fBuse_tioctl\fR is called with \fBTRUE\fR as an argument,
184 \fBncurses\fP modifies the last step in its computation
185 of screen size as follows:
186 .bP
187 checks if the \fBLINES\fR and \fBCOLUMNS\fR environment variables
188 are set to a number greater than zero.
189 .bP
190 for each, \fBncurses\fP updates the corresponding environment variable
191 with the value that it has obtained via operating system call
192 or from the terminal database.
193 .bP
194 \fBncurses\fP re-fetches the value of the environment variables so that
195 it is still the environment variables which set the screen size.
196 .PP
197 The \fBuse_env\fP and \fBuse_tioctl\fP routines combine as
198 summarized here:
199 .TS
200 center tab(/);
201 l l l
202 _ _ _
203 lw7 lw7 lw40.
204 \fIuse_env\fR/\fIuse_tioctl\fR/\fISummary\fR
205 TRUE/FALSE/T{
206 This is the default behavior.
207 \fBncurses\fP uses operating system calls
208 unless overridden by $LINES or $COLUMNS environment variables.
209 T}
210 TRUE/TRUE/T{
211 \fBncurses\fP updates $LINES and $COLUMNS based on operating system calls.
212 T}
213 FALSE/TRUE/T{
214 \fBncurses\fP ignores $LINES and $COLUMNS,
215 uses operating system calls to obtain size.
216 T}
217 FALSE/FALSE/T{
218 \fBncurses\fP relies on the terminal database to determine size.
219 T}
220 .TE
221 .SS putwin/getwin
222 .PP
223 The \fBputwin\fR routine writes all data associated
224 with window (or pad) \fIwin\fR into
225 the file to which \fIfilep\fR points.
226 This information can be later retrieved
227 using the \fBgetwin\fR function.
228 .PP
229 The \fBgetwin\fR routine reads window related data stored in the file by
230 \fBputwin\fR.
231 The routine then creates and initializes a new window using that
232 data.
233 It returns a pointer to the new window.
234 There are a few caveats:
235 .bP
236 the data written is a copy of the \fBWINDOW\fP structure,
237 and its associated character cells.
238 The format differs between the wide-character (\fBncursesw\fP) and
239 non-wide (\fBncurses\fP) libraries.
240 You can transfer data between the two, however.
241 .bP
242 the retrieved window is always created as a top-level window (or pad),
243 rather than a subwindow.
244 .bP
245 the window's character cells contain the color pair \fIvalue\fP,
246 but not the actual color \fInumbers\fP.
247 If cells in the retrieved window use color pairs which have not been
248 created in the application using \fBinit_pair\fP,
249 they will not be colored when the window is refreshed.
250 .SS delay_output
251 .PP
252 The \fBdelay_output\fR routine inserts an \fIms\fR millisecond pause
253 in output.
254 This routine should not be used extensively because
255 padding characters are used rather than a CPU pause.
256 If no padding character is specified,
257 this uses \fBnapms\fR to perform the delay.
258 .SS flushinp
259 .PP
260 The \fBflushinp\fR 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\fR, routines that return an integer return \fBERR\fR
264 upon failure and \fBOK\fR (SVr4 specifies only "an integer value other than
265 \fBERR\fR") upon successful completion.
266 .PP
267 Routines that return pointers return \fBNULL\fR 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\fR
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 .PP
282 The SVr4 documentation describes the action of \fBfilter\fR only in the vaguest
283 terms.
284 The description here is adapted from the XSI Curses standard (which
285 erroneously fails to describe the disabling of \fBcuu\fR).
286 .SS keyname
287 .PP
288 The \fBkeyname\fP function may return the names of user-defined
289 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
290 option of \fB@TIC@\fP.
291 This implementation automatically assigns at run-time keycodes to
292 user-defined strings which begin with \*(``k\*(''.
293 The keycodes start at KEY_MAX, but are not guaranteed to be
294 the same value for different runs because user-defined codes are
295 merged from all terminal descriptions which have been loaded.
296 The \fBuse_extended_names\fP(3X) function controls whether this data is
297 loaded when the terminal description is read by the library.
298 .SS nofilter/use_tioctl
299 .PP
300 The \fBnofilter\fP and \fBuse_tioctl\fP routines are specific to \fBncurses\fP.
301 They were not supported on Version 7, BSD or System V implementations.
302 It is recommended that any code depending on \fBncurses\fP extensions
303 be conditioned using NCURSES_VERSION.
304 .SS putwin/getwin
305 .PP
306 The \fBputwin\fP and \fBgetwin\fP functions have several issues with
307 portability:
308 .bP
309 The files written and read by these functions
310 use an implementation-specific format.
311 Although the format is an obvious target for standardization,
312 it has been overlooked.
313 .IP
314 Interestingly enough, according to the copyright dates in Solaris source,
315 the functions (along with \fBscr_init\fP, etc.) originated with
316 the University of California, Berkeley (in 1982)
317 and were later (in 1988) incorporated into SVr4.
318 Oddly, there are no such functions in the 4.3BSD curses sources.
319 .bP
320 Most implementations simply dump the binary \fBWINDOW\fP structure to the file.
321 These include SVr4 curses, NetBSD and PDCurses,
322 as well as older \fBncurses\fP versions.
323 This implementation
324 (as well as the X/Open variant of Solaris curses, dated 1995)
325 uses textual dumps.
326 .IP
327 The implementations which use binary dumps use block-I/O
328 (the \fBfwrite\fP and \fBfread\fP functions).
329 Those that use textual dumps use buffered-I/O.
330 A few applications may happen to write extra data in the file using
331 these functions.
332 Doing that can run into problems mixing block- and buffered-I/O.
333 This implementation reduces the problem on writes by flushing the output.
334 However, reading from a file written using mixed schemes may not be successful.
335 .SS unctrl/wunctrl
336 .PP
337 The XSI Curses standard, Issue 4 describes these functions.
338 It states that \fBunctrl\fR and \fBwunctrl\fR will return a null pointer if
339 unsuccessful, but does not define any error conditions.
340 This implementation checks for three cases:
341 .bP
342 the parameter is a 7-bit US\-ASCII code.
343 This is the case that X/Open Curses documented.
344 .bP
345 the parameter is in the range 128\-159, i.e., a C1 control code.
346 If \fBuse_legacy_coding\fP has been called with a \fB2\fP parameter,
347 \fBunctrl\fP returns the parameter, i.e., a one-character string with
348 the parameter as the first character.
349 Otherwise, it returns \*(``~@\*('', \*(``~A\*('', etc.,
350 analogous to \*(``^@\*('', \*(``^A\*('', C0 controls.
351 .IP
352 X/Open Curses does not document whether \fBunctrl\fP can be called before
353 initializing curses.
354 This implementation permits that,
355 and returns the \*(``~@\*('', etc., values in that case.
356 .bP
357 parameter values outside the 0 to 255 range.
358 \fBunctrl\fP returns a null pointer.
359 .PP
360 The strings returned by \fBunctrl\fR in this implementation are determined
361 at compile time,
362 showing C1 controls from the upper-128 codes
363 with a \*(``~\*('' prefix rather than \*(``^\*(''.
364 Other implementations have different conventions.
365 For example, they may show both sets of control characters with \*(``^\*('',
366 and strip the parameter to 7 bits.
367 Or they may ignore C1 controls and treat all of the upper-128 codes as
368 printable.
369 This implementation uses 8 bits but does not modify the string to reflect
370 locale.
371 The \fBuse_legacy_coding\fP function allows the caller to
372 change the output of \fBunctrl\fP.
373 .PP
374 Likewise, the \fBmeta\fP(3X) function allows the caller to change the
375 output of \fBkeyname\fP, i.e.,
376 it determines whether to use the \*(``M\-\*('' prefix
377 for \*(``meta\*('' keys (codes in the range 128 to 255).
378 Both \fBuse_legacy_coding\fP and \fBmeta\fP succeed only after
379 curses is initialized.
380 X/Open Curses does not document the treatment of codes 128 to 159.
381 When treating them as \*(``meta\*('' keys
382 (or if \fBkeyname\fP is called before initializing curses),
383 this implementation returns strings \*(``M\-^@\*('', \*(``M\-^A\*('', etc.
384 .PP
385 X/Open Curses documents \fBunctrl\fP as declared in \fB<unctrl.h>\fP,
386 which \fBncurses\fP does.
387 However, \fBncurses\fP' \fB<curses.h>\fP includes \fB<unctrl.h>\fP,
388 matching the behavior of SVr4 curses.
389 Other implementations may not do that.
390 .SS use_env/use_tioctl
391 .PP
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\fR(3X)).
396 This feature of \fBuse_env\fP
397 is not provided by other implementation of curses.
398 .SH SEE ALSO
399 \fBlegacy_coding\fR(3X),
400 \fBcurses\fR(3X),
401 \fBcurs_initscr\fR(3X),
402 \fBcurs_inopts\fR(3X),
403 \fBcurs_kernel\fR(3X),
404 \fBcurs_scr_dump\fR(3X),
405 \fBcurs_sp_funcs\fR(3X),
406 \fBcurs_variables\fR(3X),
407 \fBlegacy_coding\fR(3X).