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