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