]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
ncurses 6.0 - patch 20160730
[ncurses.git] / man / curs_util.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2013,2015 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.43 2015/06/06 23:36:27 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 .IP \(bu 4
38 ..
39 .na
40 .hy 0
41 .SH NAME
42 \fBdelay_output\fR,
43 \fBfilter\fR,
44 \fBflushinp\fR,
45 \fBgetwin\fR,
46 \fBkey_name\fR,
47 \fBkeyname\fR,
48 \fBnofilter\fR,
49 \fBputwin\fR,
50 \fBunctrl\fR,
51 \fBuse_env\fR,
52 \fBuse_tioctl\fR,
53 \fBwunctrl\fR \- miscellaneous \fBcurses\fR utility routines
54 .ad
55 .hy
56 .SH SYNOPSIS
57 \fB#include <curses.h>\fR
58 .sp
59 \fBchar *unctrl(chtype c);\fR
60 .br
61 \fBwchar_t *wunctrl(cchar_t *c);\fR
62 .br
63 \fBchar *keyname(int c);\fR
64 .br
65 \fBchar *key_name(wchar_t w);\fR
66 .br
67 \fBvoid filter(void);\fR
68 .br
69 \fBvoid nofilter(void);\fR
70 .br
71 \fBvoid use_env(bool f);\fR
72 .br
73 \fBvoid use_tioctl(bool f);\fR
74 .br
75 \fBint putwin(WINDOW *win, FILE *filep);\fR
76 .br
77 \fBWINDOW *getwin(FILE *filep);\fR
78 .br
79 \fBint delay_output(int ms);\fR
80 .br
81 \fBint flushinp(void);\fR
82 .br
83 .SH DESCRIPTION
84 .SS unctrl
85 .PP
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
91 a wide character.
92 .SS keyname/key_name
93 .PP
94 The \fBkeyname\fR routine returns a character string
95 corresponding to the key \fIc\fR:
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^\fR\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 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.
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, which some implementations
117 return rather than null.
118 .LP
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.
123 .SS filter/nofilter
124 .PP
125 The \fBfilter\fR routine, if used, must be called before \fBinitscr\fR or
126 \fBnewterm\fR are called.
127 The effect is that, during those calls, \fBLINES\fR
128 is set to 1; the capabilities \fBclear\fR, \fBcup\fR, \fBcud\fR, \fBcud1\fR,
129 \fBcuu1\fR, \fBcuu\fR, \fBvpa\fR are disabled; and the \fBhome\fR string is
130 set to the value of \fBcr\fR.
131 .PP
132 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
133 call.
134 That allows the caller to initialize a screen on a different device,
135 using a different value of \fB$TERM\fP.
136 The limitation arises because the \fBfilter\fP routine modifies the
137 in-memory copy of the terminal information.
138 .SS use_env
139 .PP
140 The \fBuse_env\fR routine, if used,
141 should be called before \fBinitscr\fR or
142 \fBnewterm\fR are called
143 (because those compute the screen size).
144 It modifies the way \fBncurses\fP treats environment variables
145 when determining the screen size.
146 .bP
147 Normally ncurses looks first at the terminal database for the screen size.
148 .IP
149 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
150 it stops here unless
151 If \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
152 .bP
153 Then it asks for the screen size via operating system calls.
154 If successful,
155 it overrides the values from the terminal database.
156 .bP
157 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
158 ncurses examines the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
159 using a value in those to override the results
160 from the operating system or terminal database.
161 .IP
162 Ncurses also updates the screen size in response to SIGWINCH,
163 unless overridden by the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
164 .SS use_tioctl
165 .PP
166 The \fBuse_tioctl\fR routine, if used,
167 should be called before \fBinitscr\fR or \fBnewterm\fR are called
168 (because those compute the screen size).
169 After \fBuse_tioctl\fR is called with \fBTRUE\fR as an argument,
170 ncurses modifies the last step in its computation of screen size as follows:
171 .bP
172 checks if the \fBLINES\fR and \fBCOLUMNS\fR environment variables
173 are set to a number greater than zero.
174 .bP
175 for each, ncurses updates the corresponding environment variable
176 with the value that it has obtained via operating system call
177 or from the terminal database.
178 .bP
179 ncurses re-fetches the value of the environment variables so that
180 it is still the environment variables which set the screen size.
181 .PP
182 The \fBuse_env\fP and \fBuse_tioctl\fP routines combine as
183 summarized here:
184 .TS
185 center tab(/);
186 l l l
187 _ _ _
188 lw7 lw7 lw40.
189 \fIuse_env\fR/\fIuse_tioctl\fR/\fISummary\fR
190 TRUE/FALSE/T{
191 This is the default behavior.
192 ncurses uses operating system calls
193 unless overridden by $LINES or $COLUMNS environment variables.
194 T}
195 TRUE/TRUE/T{
196 ncurses updates $LINES and $COLUMNS based on operating system calls.
197 T}
198 FALSE/TRUE/T{
199 ncurses ignores $LINES and $COLUMNS, uses operating system calls to obtain size.
200 T}
201 FALSE/FALSE/T{
202 ncurses relies on the terminal database to determine size.
203 T}
204 .TE
205 .SS putwin/getwin
206 .PP
207 The \fBputwin\fR routine writes all data associated
208 with window (or pad) \fIwin\fR into
209 the file to which \fIfilep\fR points.
210 This information can be later retrieved
211 using the \fBgetwin\fR function.
212 .PP
213 The \fBgetwin\fR routine reads window related data stored in the file by
214 \fBputwin\fR.
215 The routine then creates and initializes a new window using that
216 data.
217 It returns a pointer to the new window.
218 There are a few caveats:
219 .bP
220 the data written is a copy of the \fBWINDOW\fP structure,
221 and its associated character cells.
222 The format differs between the wide-character (ncursesw) and
223 non-wide (ncurses) libraries.
224 You can transfer data between the two, however.
225 .bP
226 the retrieved window is always created as a top-level window (or pad),
227 rather than a subwindow.
228 .bP
229 the window's character cells contain the color pair \fIvalue\fP,
230 but not the actual color \fInumbers\fP.
231 If cells in the retrieved window use color pairs which have not been
232 created in the application using \fBinit_pair\fP,
233 they will not be colored when the window is refreshed.
234 .SS delay_output
235 .PP
236 The \fBdelay_output\fR routine inserts an \fIms\fR millisecond pause
237 in output.
238 This routine should not be used extensively because
239 padding characters are used rather than a CPU pause.
240 If no padding character is specified,
241 this uses \fBnapms\fR to perform the delay.
242 .SS flushinp
243 .PP
244 The \fBflushinp\fR routine throws away any typeahead that has been typed by the
245 user and has not yet been read by the program.
246 .SH RETURN VALUE
247 Except for \fBflushinp\fR, routines that return an integer return \fBERR\fR
248 upon failure and \fBOK\fR (SVr4 specifies only "an integer value other than
249 \fBERR\fR") upon successful completion.
250 .PP
251 Routines that return pointers return \fBNULL\fR on error.
252 .PP
253 X/Open does not define any error conditions.
254 In this implementation
255 .RS 3
256 .TP 5
257 \fBflushinp\fR
258 returns an error if the terminal was not initialized.
259 .TP 5
260 \fBmeta\fR
261 returns an error if the terminal was not initialized.
262 .TP 5
263 \fBputwin\fP
264 returns an error if the associated \fBfwrite\fP calls return an error.
265 .RE
266 .SH PORTABILITY
267 .SS filter
268 .PP
269 The SVr4 documentation describes the action of \fBfilter\fR only in the vaguest
270 terms.
271 The description here is adapted from the XSI Curses standard (which
272 erroneously fails to describe the disabling of \fBcuu\fR).
273 .SS keyname
274 .PP
275 The \fBkeyname\fP function may return the names of user-defined
276 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
277 option of \fB@TIC@\fP.
278 This implementation automatically assigns at run-time keycodes to
279 user-defined strings which begin with "k".
280 The keycodes start at KEY_MAX, but are not guaranteed to be
281 the same value for different runs because user-defined codes are
282 merged from all terminal descriptions which have been loaded.
283 The \fBuse_extended_names\fP function controls whether this data is
284 loaded when the terminal description is read by the library.
285 .SS nofilter/use_tioctl
286 .PP
287 The \fBnofilter\fP and \fBuse_tioctl\fP routines are specific to ncurses.
288 They were not supported on Version 7, BSD or System V implementations.
289 It is recommended that any code depending on ncurses extensions
290 be conditioned using NCURSES_VERSION.
291 .SS putwin/getwin
292 .PP
293 The \fBputwin\fP and \fBgetwin\fP functions have several issues with
294 portability:
295 .bP
296 The files written and read by these functions
297 use an implementation-specific format.
298 Although the format is an obvious target for standardization,
299 it has been overlooked.
300 .IP
301 Interestingly enough, according to the copyright dates in Solaris source,
302 the functions (along with \fBscr_init\fP, etc.) originated with
303 the University of California, Berkeley (in 1982)
304 and were later (in 1988) incorporated into SVr4.
305 Oddly, there are no such functions in the 4.3BSD curses sources.
306 .bP
307 Most implementations simply dump the binary \fBWINDOW\fP structure to the file.
308 These include SVr4 curses, NetBSD and PDCurses, as well as older ncurses versions.
309 This implementation (as well as the X/Open variant of Solaris curses, dated 1995)
310 uses textual dumps.
311 .IP
312 The implementations which use binary dumps use block-I/O
313 (the \fBfwrite\fP and \fBfread\fP functions).
314 Those that use textual dumps use buffered-I/O.
315 A few applications may happen to write extra data in the file using
316 these functions.
317 Doing that can run into problems mixing block- and buffered-I/O.
318 This implementation reduces the problem on writes by flushing the output.
319 However, reading from a file written using mixed schemes may not be successful.
320 .SS unctrl/wunctrl
321 .PP
322 The XSI Curses standard, Issue 4 describes these functions.
323 It states that \fBunctrl\fR and \fBwunctrl\fR will return a null pointer if
324 unsuccessful, but does not define any error conditions.
325 This implementation checks for three cases:
326 .bP
327 the parameter is a 7-bit US\-ASCII code.
328 This is the case that X/Open Curses documented.
329 .bP
330 the parameter is in the range 128\-159, i.e., a C1 control code.
331 If \fBuse_legacy_coding\fP has been called with a \fB2\fP parameter,
332 \fBunctrl\fP returns the parameter, i.e., a one-character string with
333 the parameter as the first character.
334 Otherwise, it returns \*(``~@\*('', \*(``~A\*('', etc.,
335 analogous to \*(``^@\*('', \*(``^A\*('', C0 controls.
336 .IP
337 X/Open Curses does not document whether \fBunctrl\fP can be called before
338 initializing curses.
339 This implementation permits that,
340 and returns the \*(``~@\*('', etc., values in that case.
341 .bP
342 parameter values outside the 0 to 255 range.
343 \fBunctrl\fP returns a null pointer.
344 .PP
345 The strings returned by \fBunctrl\fR in this implementation are determined
346 at compile time,
347 showing C1 controls from the upper-128 codes with a `~' prefix rather than `^'.
348 Other implementations have different conventions.
349 For example, they may show both sets of control characters with `^',
350 and strip the parameter to 7 bits.
351 Or they may ignore C1 controls and treat all of the upper-128 codes as
352 printable.
353 This implementation uses 8 bits but does not modify the string to reflect
354 locale.
355 The \fBuse_legacy_coding\fP function allows the caller to
356 change the output of \fBunctrl\fP.
357 .PP
358 Likewise, the \fBmeta\fP function allows the caller to change the
359 output of \fBkeyname\fP, i.e.,
360 it determines whether to use the `M\-' prefix
361 for \*(``meta\*('' keys (codes in the range 128 to 255).
362 Both \fBuse_legacy_coding\fP and \fBmeta\fP succeed only after
363 curses is initialized.
364 X/Open Curses does not document the treatment of codes 128 to 159.
365 When treating them as \*(``meta\*('' keys
366 (or if \fBkeyname\fP is called before initializing curses),
367 this implementation returns strings \*(``M\-^@\*('', \*(``M\-^A\*('', etc.
368 .SH SEE ALSO
369 \fBlegacy_coding\fR(3X),
370 \fBcurses\fR(3X),
371 \fBcurs_initscr\fR(3X),
372 \fBcurs_kernel\fR(3X),
373 \fBcurs_scr_dump\fR(3X),
374 \fBcurs_variables\fR(3X),
375 \fBlegacy_coding\fR(3X).