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