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