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