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