]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_util.3x
28e0f2b1a3306eef2fe39e301009d49d751b0e31
[ncurses.git] / man / curs_util.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2008,2010 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.30 2010/09/18 20:24:41 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 \fBwunctrl\fR \- miscellaneous \fBcurses\fR utility routines
48 .ad
49 .hy
50 .SH SYNOPSIS
51 \fB#include <curses.h>\fR
52 .sp
53 \fBchar *unctrl(chtype c);\fR
54 .br
55 \fBwchar_t *wunctrl(cchar_t *c);\fR
56 .br
57 \fBchar *keyname(int c);\fR
58 .br
59 \fBchar *key_name(wchar_t w);\fR
60 .br
61 \fBvoid filter(void);\fR
62 .br
63 \fBvoid nofilter(void);\fR
64 .br
65 \fBvoid use_env(bool f);\fR
66 .br
67 \fBint putwin(WINDOW *win, FILE *filep);\fR
68 .br
69 \fBWINDOW *getwin(FILE *filep);\fR
70 .br
71 \fBint delay_output(int ms);\fR
72 .br
73 \fBint flushinp(void);\fR
74 .br
75 .SH DESCRIPTION
76 The \fBunctrl\fR routine returns a character string which is a printable
77 representation of the character \fIc\fR, ignoring attributes.
78 Control characters are displayed in the \fB^\fR\fIX\fR notation.
79 Printing characters are displayed as is.
80 The corresponding \fBwunctrl\fR returns a printable representation of
81 a wide character.
82 .PP
83 The \fBkeyname\fR routine returns a character string corresponding to the key \fIc\fR:
84 .RS 3
85 .bP
86 Printable characters are displayed as themselves, e.g., a one-character string containing the key.
87 .bP
88 Control characters are displayed in the \fB^\fR\fIX\fR notation.
89 .bP
90 DEL (character 127) is displayed as \fB^?\fP.
91 .bP
92 Values above 128 are either meta characters
93 (if the screen has not been initialized,
94 or if \fBmeta\fP has been called with a TRUE parameter),
95 shown in the \fBM\-\fR\fIX\fR notation,
96 or are displayed as themselves.
97 In the latter case, the values may not be printable;
98 this follows the X/Open specification.
99 .bP
100 Values above 256 may be the names of the names of function keys.
101 .bP
102 Otherwise (if there is no corresponding name) the function returns null,
103 to denote an error.
104 X/Open also lists an "UNKNOWN KEY" return value, which some implementations
105 return rather than null.
106 .RE
107 .LP
108 The corresponding \fBkey_name\fR returns a character string corresponding
109 to the wide-character value \fIw\fR.
110 The two functions do not return the same set of strings;
111 the latter returns null where the former would display a meta character.
112 .PP
113 The \fBfilter\fR routine, if used, must be called before \fBinitscr\fR or
114 \fBnewterm\fR are called.  The effect is that, during those calls, \fBLINES\fR
115 is set to 1; the capabilities \fBclear\fR, \fBcup\fR, \fBcud\fR, \fBcud1\fR,
116 \fBcuu1\fR, \fBcuu\fR, \fBvpa\fR are disabled; and the \fBhome\fR string is
117 set to the value of \fBcr\fR.
118 .PP
119 The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP
120 call.
121 That allows the caller to initialize a screen on a different device,
122 using a different value of \fB$TERM\fP.
123 The limitation arises because the \fBfilter\fP routine modifies the
124 in-memory copy of the terminal information.
125 .PP
126 The \fBuse_env\fR routine, if used, is called before \fBinitscr\fR or
127 \fBnewterm\fR are called.  When called with \fBFALSE\fR as an
128 argument, the values of \fBlines\fR and \fBcolumns\fR specified in the
129 \fIterminfo\fR database will be used, even if environment variables
130 \fBLINES\fR and \fBCOLUMNS\fR (used by default) are set, or if
131 \fBcurses\fR is running in a window (in which case default behavior
132 would be to use the window size if \fBLINES\fR and \fBCOLUMNS\fR are
133 not set).
134 Note that setting \fBLINES\fR or \fBCOLUMNS\fR overrides the
135 corresponding size which may be obtained from the operating system.
136 .PP
137 The \fBputwin\fR routine writes all data associated with window \fIwin\fR into
138 the file to which \fIfilep\fR points.  This information can be later retrieved
139 using the \fBgetwin\fR function.
140 .PP
141 The \fBgetwin\fR routine reads window related data stored in the file by
142 \fBputwin\fR.  The routine then creates and initializes a new window using that
143 data.  It returns a pointer to the new window.
144 .PP
145 The \fBdelay_output\fR routine inserts an \fIms\fR millisecond pause
146 in output.  This routine should not be used extensively because
147 padding characters are used rather than a CPU pause.
148 If no padding character is specified, this uses \fBnapms\fR to perform the delay.
149 .PP
150 The \fBflushinp\fR routine throws away any typeahead that has been typed by the
151 user and has not yet been read by the program.
152 .SH RETURN VALUE
153 Except for \fBflushinp\fR, routines that return an integer return \fBERR\fR
154 upon failure and \fBOK\fR (SVr4 specifies only "an integer value other than
155 \fBERR\fR") upon successful completion.
156 .PP
157 Routines that return pointers return \fBNULL\fR on error.
158 .PP
159 X/Open does not define any error conditions.
160 In this implementation
161 .RS 3
162 .TP 5
163 \fBflushinp\fR
164 returns an error if the terminal was not initialized.
165 .TP 5
166 \fBmeta\fR
167 returns an error if the terminal was not initialized.
168 .TP 5
169 \fBputwin\fP
170 returns an error if the associated \fBfwrite\fP calls return an error.
171 .RE
172 .SH PORTABILITY
173 The XSI Curses standard, Issue 4 describes these functions.
174 It states that \fBunctrl\fR and \fBwunctrl\fR will return a null pointer if
175 unsuccessful, but does not define any error conditions.
176 This implementation checks for three cases:
177 .RS 3
178 .bP
179 the parameter is a 7-bit US\-ASCII code.
180 This is the case that X/Open Curses documented.
181 .bP
182 the parameter is in the range 128\-159, i.e., a C1 control code.
183 If \fBuse_legacy_coding\fP has been called with a \fB2\fP parameter,
184 \fBunctrl\fP returns the parameter, i.e., a one-character string with
185 the parameter as the first character.
186 Otherwise, it returns ``~@'', ``~A'', etc., analogous to ``^@'', ``^A'', C0 controls.
187 .IP
188 X/Open Curses does not document whether \fBunctrl\fP can be called before
189 initializing curses.
190 This implementation permits that,
191 and returns the ``~@'', etc., values in that case.
192 .bP
193 parameter values outside the 0 to 255 range.
194 \fBunctrl\fP returns a null pointer.
195 .RE
196 .PP
197 The SVr4 documentation describes the action of \fBfilter\fR only in the vaguest
198 terms.  The description here is adapted from the XSI Curses standard (which
199 erroneously fails to describe the disabling of \fBcuu\fR).
200 .PP
201 The strings returned by \fBunctrl\fR in this implementation are determined
202 at compile time,
203 showing C1 controls from the upper-128 codes with a `~' prefix rather than `^'.
204 Other implementations have different conventions.
205 For example, they may show both sets of control characters with `^',
206 and strip the parameter to 7 bits.
207 Or they may ignore C1 controls and treat all of the upper-128 codes as
208 printable.
209 This implementation uses 8 bits but does not modify the string to reflect
210 locale.
211 The \fBuse_legacy_coding\fP function allows the caller to
212 change the output of \fBunctrl\fP.
213 .PP
214 Likewise, the \fBmeta\fP function allows the caller to change the
215 output of \fBkeyname\fP, i.e.,
216 it determines whether to use the `M\-' prefix
217 for ``meta'' keys (codes in the range 128 to 255).
218 Both \fBuse_legacy_coding\fP and \fBmeta\fP succeed only after
219 curses is initialized. 
220 X/Open Curses does not document the treatment of codes 128 to 159.
221 When treating them as ``meta'' keys
222 (or if \fBkeyname\fP is called before initializing curses),
223 this implementation returns strings ``M\-^@'', ``M\-^A'', etc.
224 .PP
225 The \fBkeyname\fP function may return the names of user-defined
226 string capabilities which are defined in the terminfo entry via the \fB\-x\fP
227 option of \fBtic\fP.
228 This implementation automatically assigns at run-time keycodes to 
229 user-defined strings which begin with "k".
230 The keycodes start at KEY_MAX, but are not guaranteed to be 
231 the same value for different runs because user-defined codes are
232 merged from all terminal descriptions which have been loaded.
233 The \fBuse_extended_names\fP function controls whether this data is
234 loaded when the terminal description is read by the library.
235 .PP
236 The \fBnofilter\fP routine is specific to ncurses.
237 It was not supported on Version 7, BSD or System V implementations.
238 It is recommended that any code depending on ncurses extensions
239 be conditioned using NCURSES_VERSION.
240 .SH SEE ALSO
241 \fBlegacy_coding\fR(3X),
242 \fBcurses\fR(3X),
243 \fBcurs_initscr\fR(3X),
244 \fBcurs_kernel\fR(3X),
245 \fBcurs_scr_dump\fR(3X),
246 \fBlegacy_coding\fR(3X).
247 .\"#
248 .\"# The following sets edit modes for GNU EMACS
249 .\"# Local Variables:
250 .\"# mode:nroff
251 .\"# fill-column:79
252 .\"# End: