2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2015,2017 Free Software Foundation, Inc. *
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: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
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. *
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 *
28 .\"***************************************************************************
30 .\" $Id: curs_util.3x,v 1.51 2017/10/07 21:47:25 tom Exp $
53 \fBwunctrl\fR \- miscellaneous \fBcurses\fR utility routines
57 \fB#include <curses.h>\fR
59 \fBchar *unctrl(chtype c);\fR
61 \fBwchar_t *wunctrl(cchar_t *c);\fR
63 \fBchar *keyname(int c);\fR
65 \fBchar *key_name(wchar_t w);\fR
67 \fBvoid filter(void);\fR
69 \fBvoid nofilter(void);\fR
71 \fBvoid use_env(bool f);\fR
73 \fBvoid use_tioctl(bool f);\fR
75 \fBint putwin(WINDOW *win, FILE *filep);\fR
77 \fBWINDOW *getwin(FILE *filep);\fR
79 \fBint delay_output(int ms);\fR
81 \fBint flushinp(void);\fR
86 The \fBunctrl\fR routine returns a character string which is a printable
87 representation of the character \fIc\fR, ignoring attributes.
88 Control characters are displayed in the \fB^\fR\fIX\fR notation.
89 Printing characters are displayed as is.
90 The corresponding \fBwunctrl\fR returns a printable representation of
94 The \fBkeyname\fR routine returns a character string
95 corresponding to the key \fIc\fR:
97 Printable characters are displayed as themselves,
98 e.g., a one-character string containing the key.
100 Control characters are displayed in the \fB^\fR\fIX\fR notation.
102 DEL (character 127) is displayed as \fB^?\fP.
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\-\fR\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.
112 Values above 256 may be the names of the names of function keys.
114 Otherwise (if there is no corresponding name) the function returns null,
116 X/Open also lists an "UNKNOWN KEY" return value, which some implementations
117 return rather than null.
119 The corresponding \fBkey_name\fR returns a character string corresponding
120 to the wide-character value \fIw\fR.
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.
125 The \fBfilter\fR routine, if used, must be called before \fBinitscr\fR or
126 \fBnewterm\fR are called.
127 Calling \fBfilter\fP causes these changes in initialization:
129 \fBLINES\fR is set to 1;
141 the capability \fBed\fP is disabled if \fBbce\fP is set;
143 and the \fBhome\fR string is set to the value of \fBcr\fR.
145 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
147 That allows the caller to initialize a screen on a different device,
148 using a different value of \fB$TERM\fP.
149 The limitation arises because the \fBfilter\fP routine modifies the
150 in-memory copy of the terminal information.
153 The \fBuse_env\fR routine, if used,
154 should be called before \fBinitscr\fR or
155 \fBnewterm\fR are called
156 (because those compute the screen size).
157 It modifies the way \fBncurses\fP treats environment variables
158 when determining the screen size.
160 Normally \fBncurses\fP looks first at the terminal database for the screen size.
162 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
164 \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
166 Then it asks for the screen size via operating system calls.
168 it overrides the values from the terminal database.
170 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
171 \fBncurses\fP examines the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
172 using a value in those to override the results
173 from the operating system or terminal database.
175 \fBNcurses\fP also updates the screen size in response to \fBSIGWINCH\fP,
176 unless overridden by the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
179 The \fBuse_tioctl\fR routine, if used,
180 should be called before \fBinitscr\fR or \fBnewterm\fR are called
181 (because those compute the screen size).
182 After \fBuse_tioctl\fR is called with \fBTRUE\fR as an argument,
183 \fBncurses\fP modifies the last step in its computation of screen size as follows:
185 checks if the \fBLINES\fR and \fBCOLUMNS\fR environment variables
186 are set to a number greater than zero.
188 for each, \fBncurses\fP updates the corresponding environment variable
189 with the value that it has obtained via operating system call
190 or from the terminal database.
192 \fBncurses\fP re-fetches the value of the environment variables so that
193 it is still the environment variables which set the screen size.
195 The \fBuse_env\fP and \fBuse_tioctl\fP routines combine as
202 \fIuse_env\fR/\fIuse_tioctl\fR/\fISummary\fR
204 This is the default behavior.
205 \fBncurses\fP uses operating system calls
206 unless overridden by $LINES or $COLUMNS environment variables.
209 \fBncurses\fP updates $LINES and $COLUMNS based on operating system calls.
212 \fBncurses\fP ignores $LINES and $COLUMNS, uses operating system calls to obtain size.
215 \fBncurses\fP relies on the terminal database to determine size.
220 The \fBputwin\fR routine writes all data associated
221 with window (or pad) \fIwin\fR into
222 the file to which \fIfilep\fR points.
223 This information can be later retrieved
224 using the \fBgetwin\fR function.
226 The \fBgetwin\fR routine reads window related data stored in the file by
228 The routine then creates and initializes a new window using that
230 It returns a pointer to the new window.
231 There are a few caveats:
233 the data written is a copy of the \fBWINDOW\fP structure,
234 and its associated character cells.
235 The format differs between the wide-character (ncursesw) and
236 non-wide (ncurses) libraries.
237 You can transfer data between the two, however.
239 the retrieved window is always created as a top-level window (or pad),
240 rather than a subwindow.
242 the window's character cells contain the color pair \fIvalue\fP,
243 but not the actual color \fInumbers\fP.
244 If cells in the retrieved window use color pairs which have not been
245 created in the application using \fBinit_pair\fP,
246 they will not be colored when the window is refreshed.
249 The \fBdelay_output\fR routine inserts an \fIms\fR millisecond pause
251 This routine should not be used extensively because
252 padding characters are used rather than a CPU pause.
253 If no padding character is specified,
254 this uses \fBnapms\fR to perform the delay.
257 The \fBflushinp\fR routine throws away any typeahead that has been typed by the
258 user and has not yet been read by the program.
260 Except for \fBflushinp\fR, routines that return an integer return \fBERR\fR
261 upon failure and \fBOK\fR (SVr4 specifies only "an integer value other than
262 \fBERR\fR") upon successful completion.
264 Routines that return pointers return \fBNULL\fR on error.
266 X/Open does not define any error conditions.
267 In this implementation
271 returns an error if the terminal was not initialized.
274 returns an error if the associated \fBfwrite\fP calls return an error.
279 The SVr4 documentation describes the action of \fBfilter\fR only in the vaguest
281 The description here is adapted from the XSI Curses standard (which
282 erroneously fails to describe the disabling of \fBcuu\fR).
285 The \fBkeyname\fP function may return the names of user-defined
286 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
288 This implementation automatically assigns at run-time keycodes to
289 user-defined strings which begin with "k".
290 The keycodes start at KEY_MAX, but are not guaranteed to be
291 the same value for different runs because user-defined codes are
292 merged from all terminal descriptions which have been loaded.
293 The \fBuse_extended_names\fP(3X) function controls whether this data is
294 loaded when the terminal description is read by the library.
295 .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 NCURSES_VERSION.
303 The \fBputwin\fP and \fBgetwin\fP functions have several issues with
306 The files written and read by these functions
307 use an implementation-specific format.
308 Although the format is an obvious target for standardization,
309 it has been overlooked.
311 Interestingly enough, according to the copyright dates in Solaris source,
312 the functions (along with \fBscr_init\fP, etc.) originated with
313 the University of California, Berkeley (in 1982)
314 and were later (in 1988) incorporated into SVr4.
315 Oddly, there are no such functions in the 4.3BSD curses sources.
317 Most implementations simply dump the binary \fBWINDOW\fP structure to the file.
318 These include SVr4 curses, NetBSD and PDCurses, as well as older \fBncurses\fP versions.
319 This implementation (as well as the X/Open variant of Solaris curses, dated 1995)
322 The implementations which use binary dumps use block-I/O
323 (the \fBfwrite\fP and \fBfread\fP functions).
324 Those that use textual dumps use buffered-I/O.
325 A few applications may happen to write extra data in the file using
327 Doing that can run into problems mixing block- and buffered-I/O.
328 This implementation reduces the problem on writes by flushing the output.
329 However, reading from a file written using mixed schemes may not be successful.
332 The XSI Curses standard, Issue 4 describes these functions.
333 It states that \fBunctrl\fR and \fBwunctrl\fR will return a null pointer if
334 unsuccessful, but does not define any error conditions.
335 This implementation checks for three cases:
337 the parameter is a 7-bit US\-ASCII code.
338 This is the case that X/Open Curses documented.
340 the parameter is in the range 128\-159, i.e., a C1 control code.
341 If \fBuse_legacy_coding\fP 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.
347 X/Open Curses does not document whether \fBunctrl\fP can be called before
349 This implementation permits that,
350 and returns the \*(``~@\*('', etc., values in that case.
352 parameter values outside the 0 to 255 range.
353 \fBunctrl\fP returns a null pointer.
355 The strings returned by \fBunctrl\fR in this implementation are determined
357 showing C1 controls from the upper-128 codes with a \*(``~\*('' prefix rather than \*(``^\*(''.
358 Other implementations have different conventions.
359 For example, they may show both sets of control characters with \*(``^\*('',
360 and strip the parameter to 7 bits.
361 Or they may ignore C1 controls and treat all of the upper-128 codes as
363 This implementation uses 8 bits but does not modify the string to reflect
365 The \fBuse_legacy_coding\fP function allows the caller to
366 change the output of \fBunctrl\fP.
368 Likewise, the \fBmeta\fP(3X) function allows the caller to change the
369 output of \fBkeyname\fP, i.e.,
370 it determines whether to use the \*(``M\-\*('' prefix
371 for \*(``meta\*('' keys (codes in the range 128 to 255).
372 Both \fBuse_legacy_coding\fP and \fBmeta\fP succeed only after
373 curses is initialized.
374 X/Open Curses does not document the treatment of codes 128 to 159.
375 When treating them as \*(``meta\*('' keys
376 (or if \fBkeyname\fP is called before initializing curses),
377 this implementation returns strings \*(``M\-^@\*('', \*(``M\-^A\*('', etc.
378 .SS use_env/use_tioctl
380 If \fBncurses\fP is configured to provide the sp-functions extension,
381 the state of \fBuse_env\fP and \fBuse_tioctl\fP may be updated before
382 creating each \fIscreen\fP rather than once only
383 (\fBcurs_sp_funcs\fR(3X)).
384 This feature of \fBuse_env\fP
385 is not provided by other implementation of curses.
387 \fBlegacy_coding\fR(3X),
389 \fBcurs_initscr\fR(3X),
390 \fBcurs_inopts\fR(3X),
391 \fBcurs_kernel\fR(3X),
392 \fBcurs_scr_dump\fR(3X),
393 \fBcurs_sp_funcs\fR(3X),
394 \fBcurs_variables\fR(3X),
395 \fBlegacy_coding\fR(3X).