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