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