]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
ncurses 5.9 - patch 20130119
[ncurses.git] / man / curs_util.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2011,2012 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.36 2012/07/21 18:51:10 tom Exp $
31 .TH curs_util 3X ""
32 .de bP
33 .IP \(bu 4
34 ..
35 .na
36 .hy 0
37 .SH NAME
38 \fBdelay_output\fR,
39 \fBfilter\fR,
40 \fBflushinp\fR,
41 \fBgetwin\fR,
42 \fBkey_name\fR,
43 \fBkeyname\fR,
44 \fBnofilter\fR,
45 \fBputwin\fR,
46 \fBunctrl\fR,
47 \fBuse_env\fR,
48 \fBuse_tioctl\fR,
49 \fBwunctrl\fR \- miscellaneous \fBcurses\fR utility routines
50 .ad
51 .hy
52 .SH SYNOPSIS
53 \fB#include <curses.h>\fR
54 .sp
55 \fBchar *unctrl(chtype c);\fR
56 .br
57 \fBwchar_t *wunctrl(cchar_t *c);\fR
58 .br
59 \fBchar *keyname(int c);\fR
60 .br
61 \fBchar *key_name(wchar_t w);\fR
62 .br
63 \fBvoid filter(void);\fR
64 .br
65 \fBvoid nofilter(void);\fR
66 .br
67 \fBvoid use_env(bool f);\fR
68 .br
69 \fBvoid use_tioctl(bool f);\fR
70 .br
71 \fBint putwin(WINDOW *win, FILE *filep);\fR
72 .br
73 \fBWINDOW *getwin(FILE *filep);\fR
74 .br
75 \fBint delay_output(int ms);\fR
76 .br
77 \fBint flushinp(void);\fR
78 .br
79 .SH DESCRIPTION
80 The \fBunctrl\fR routine returns a character string which is a printable
81 representation of the character \fIc\fR, ignoring attributes.
82 Control characters are displayed in the \fB^\fR\fIX\fR notation.
83 Printing characters are displayed as is.
84 The corresponding \fBwunctrl\fR returns a printable representation of
85 a wide character.
86 .PP
87 The \fBkeyname\fR routine returns a character string corresponding to the key \fIc\fR:
88 .RS 3
89 .bP
90 Printable characters are displayed as themselves, e.g., a one-character string containing the key.
91 .bP
92 Control characters are displayed in the \fB^\fR\fIX\fR notation.
93 .bP
94 DEL (character 127) is displayed as \fB^?\fP.
95 .bP
96 Values above 128 are either meta characters
97 (if the screen has not been initialized,
98 or if \fBmeta\fP has been called with a TRUE parameter),
99 shown in the \fBM\-\fR\fIX\fR notation,
100 or are displayed as themselves.
101 In the latter case, the values may not be printable;
102 this follows the X/Open specification.
103 .bP
104 Values above 256 may be the names of the names of function keys.
105 .bP
106 Otherwise (if there is no corresponding name) the function returns null,
107 to denote an error.
108 X/Open also lists an "UNKNOWN KEY" return value, which some implementations
109 return rather than null.
110 .RE
111 .LP
112 The corresponding \fBkey_name\fR returns a character string corresponding
113 to the wide-character value \fIw\fR.
114 The two functions do not return the same set of strings;
115 the latter returns null where the former would display a meta character.
116 .PP
117 The \fBfilter\fR routine, if used, must be called before \fBinitscr\fR or
118 \fBnewterm\fR are called.  The effect is that, during those calls, \fBLINES\fR
119 is set to 1; the capabilities \fBclear\fR, \fBcup\fR, \fBcud\fR, \fBcud1\fR,
120 \fBcuu1\fR, \fBcuu\fR, \fBvpa\fR are disabled; and the \fBhome\fR string is
121 set to the value of \fBcr\fR.
122 .PP
123 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
124 call.
125 That allows the caller to initialize a screen on a different device,
126 using a different value of \fB$TERM\fP.
127 The limitation arises because the \fBfilter\fP routine modifies the
128 in-memory copy of the terminal information.
129 .PP
130 The \fBuse_env\fR routine, if used,
131 should be called before \fBinitscr\fR or
132 \fBnewterm\fR are called
133 (because those compute the screen size).
134 It modifies the way \fBncurses\fP treats environment variables
135 when determining the screen size.
136 .bP
137 Normally ncurses looks first at the terminal database for the screen size.
138 .IP
139 If \fBuse_env\fP was called with \fBFALSE\fP for parameter,
140 it stops here unless
141 If \fBuse_tioctl\fP was also called with \fBTRUE\fP for parameter.
142 .bP
143 Then it asks for the screen size via operating system calls.
144 If successful,
145 it overrides the values from the terminal database.
146 .bP
147 Finally (unless \fBuse_env\fP was called with \fBFALSE\fP parameter),
148 ncurses examines the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
149 using a value in those to override the results
150 from the operating system or terminal database.
151 .IP
152 Ncurses also updates the screen size in response to SIGWINCH,
153 unless overridden by the \fBLINES\fR or \fBCOLUMNS\fR environment variables,
154 .PP
155 The \fBuse_tioctl\fR routine, if used,
156 should be called before \fBinitscr\fR or \fBnewterm\fR are called
157 (because those compute the screen size).
158 After \fBuse_tioctl\fR is called with \fBTRUE\fR as an argument,
159 ncurses modifies the last step in its computation of screen size as follows:
160 .bP
161 checks if the \fBLINES\fR and \fBCOLUMNS\fR environment variables
162 are set to a number greater than zero.
163 .bP
164 for each, ncurses updates the corresponding environment variable
165 with the value that it has obtained via operating system call
166 or from the terminal database.
167 .bP
168 ncurses re-fetches the value of the environment variables so that
169 it is still the environment variables which set the screen size.
170 .PP
171 The \fBuse_env\fP and \fBuse_tioctl\fP routines combine as
172 summarized here:
173 .TS
174 center tab(/);
175 l l l
176 _ _ _
177 lw7 lw7 lw40.
178 \fIuse_env\fR/\fIuse_tioctl\fR/\fISummary\fR
179 TRUE/FALSE/T{
180 This is the default behavior.
181 ncurses uses operating system calls
182 unless overridden by $LINES or $COLUMNS environment variables.
183 T}
184 TRUE/TRUE/T{
185 ncurses updates $LINES and $COLUMNS based on operating system calls.
186 T}
187 FALSE/TRUE/T{
188 ncurses ignores $LINES and $COLUMNS, uses operating system calls to obtain size.
189 T}
190 FALSE/FALSE/T{
191 ncurses relies on the terminal database to determine size.
192 T}
193 .TE
194 .PP
195 The \fBputwin\fR routine writes all data associated with window \fIwin\fR into
196 the file to which \fIfilep\fR points.  This information can be later retrieved
197 using the \fBgetwin\fR function.
198 .PP
199 The \fBgetwin\fR routine reads window related data stored in the file by
200 \fBputwin\fR.  The routine then creates and initializes a new window using that
201 data.  It returns a pointer to the new window.
202 .PP
203 The \fBdelay_output\fR routine inserts an \fIms\fR millisecond pause
204 in output.  This routine should not be used extensively because
205 padding characters are used rather than a CPU pause.
206 If no padding character is specified, this uses \fBnapms\fR to perform the delay.
207 .PP
208 The \fBflushinp\fR routine throws away any typeahead that has been typed by the
209 user and has not yet been read by the program.
210 .SH RETURN VALUE
211 Except for \fBflushinp\fR, routines that return an integer return \fBERR\fR
212 upon failure and \fBOK\fR (SVr4 specifies only "an integer value other than
213 \fBERR\fR") upon successful completion.
214 .PP
215 Routines that return pointers return \fBNULL\fR on error.
216 .PP
217 X/Open does not define any error conditions.
218 In this implementation
219 .RS 3
220 .TP 5
221 \fBflushinp\fR
222 returns an error if the terminal was not initialized.
223 .TP 5
224 \fBmeta\fR
225 returns an error if the terminal was not initialized.
226 .TP 5
227 \fBputwin\fP
228 returns an error if the associated \fBfwrite\fP calls return an error.
229 .RE
230 .SH PORTABILITY
231 The XSI Curses standard, Issue 4 describes these functions.
232 It states that \fBunctrl\fR and \fBwunctrl\fR will return a null pointer if
233 unsuccessful, but does not define any error conditions.
234 This implementation checks for three cases:
235 .RS 3
236 .bP
237 the parameter is a 7-bit US\-ASCII code.
238 This is the case that X/Open Curses documented.
239 .bP
240 the parameter is in the range 128\-159, i.e., a C1 control code.
241 If \fBuse_legacy_coding\fP has been called with a \fB2\fP parameter,
242 \fBunctrl\fP returns the parameter, i.e., a one-character string with
243 the parameter as the first character.
244 Otherwise, it returns ``~@'', ``~A'', etc., analogous to ``^@'', ``^A'', C0 controls.
245 .IP
246 X/Open Curses does not document whether \fBunctrl\fP can be called before
247 initializing curses.
248 This implementation permits that,
249 and returns the ``~@'', etc., values in that case.
250 .bP
251 parameter values outside the 0 to 255 range.
252 \fBunctrl\fP returns a null pointer.
253 .RE
254 .PP
255 The SVr4 documentation describes the action of \fBfilter\fR only in the vaguest
256 terms.  The description here is adapted from the XSI Curses standard (which
257 erroneously fails to describe the disabling of \fBcuu\fR).
258 .PP
259 The strings returned by \fBunctrl\fR in this implementation are determined
260 at compile time,
261 showing C1 controls from the upper-128 codes with a `~' prefix rather than `^'.
262 Other implementations have different conventions.
263 For example, they may show both sets of control characters with `^',
264 and strip the parameter to 7 bits.
265 Or they may ignore C1 controls and treat all of the upper-128 codes as
266 printable.
267 This implementation uses 8 bits but does not modify the string to reflect
268 locale.
269 The \fBuse_legacy_coding\fP function allows the caller to
270 change the output of \fBunctrl\fP.
271 .PP
272 Likewise, the \fBmeta\fP function allows the caller to change the
273 output of \fBkeyname\fP, i.e.,
274 it determines whether to use the `M\-' prefix
275 for ``meta'' keys (codes in the range 128 to 255).
276 Both \fBuse_legacy_coding\fP and \fBmeta\fP succeed only after
277 curses is initialized. 
278 X/Open Curses does not document the treatment of codes 128 to 159.
279 When treating them as ``meta'' keys
280 (or if \fBkeyname\fP is called before initializing curses),
281 this implementation returns strings ``M\-^@'', ``M\-^A'', etc.
282 .PP
283 The \fBkeyname\fP function may return the names of user-defined
284 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
285 option of \fB@TIC@\fP.
286 This implementation automatically assigns at run-time keycodes to 
287 user-defined strings which begin with "k".
288 The keycodes start at KEY_MAX, but are not guaranteed to be 
289 the same value for different runs because user-defined codes are
290 merged from all terminal descriptions which have been loaded.
291 The \fBuse_extended_names\fP function controls whether this data is
292 loaded when the terminal description is read by the library.
293 .PP
294 The \fBnofilter\fP and \fBuse_tioctl\fP routines are specific to ncurses.
295 They were not supported on Version 7, BSD or System V implementations.
296 It is recommended that any code depending on ncurses extensions
297 be conditioned using NCURSES_VERSION.
298 .SH SEE ALSO
299 \fBlegacy_coding\fR(3X),
300 \fBcurses\fR(3X),
301 \fBcurs_initscr\fR(3X),
302 \fBcurs_kernel\fR(3X),
303 \fBcurs_scr_dump\fR(3X),
304 \fBcurs_variables\fR(3X),
305 \fBlegacy_coding\fR(3X).