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