1curs_util(3X)                                                    curs_util(3X)
2
3
4

NAME

6       delay_output, filter, flushinp, getwin, key_name, keyname, nofilter,
7       putwin, unctrl, use_env, use_tioctl, wunctrl - miscellaneous curses
8       utility routines
9

SYNOPSIS

11       #include <curses.h>
12
13       const char *unctrl(chtype c);
14       wchar_t *wunctrl(cchar_t *c);
15
16       const char *keyname(int c);
17       const char *key_name(wchar_t w);
18
19       void filter(void);
20       void nofilter(void);
21
22       void use_env(bool f);
23       void use_tioctl(bool f);
24
25       int putwin(WINDOW *win, FILE *filep);
26       WINDOW *getwin(FILE *filep);
27
28       int delay_output(int ms);
29       int flushinp(void);
30

DESCRIPTION

32   unctrl
33       The unctrl routine returns a character string which is a printable rep‐
34       resentation of the character c, ignoring attributes.   Control  charac‐
35       ters  are  displayed  in the ^X notation.  Printing characters are dis‐
36       played as is.
37
38       The corresponding wunctrl returns a printable representation of a  wide
39       character.
40
41   keyname/key_name
42       The keyname routine returns a character string corresponding to the key
43       c:
44
45       •   Printable characters are displayed as themselves, e.g., a one-char‐
46           acter string containing the key.
47
48       •   Control characters are displayed in the ^X notation.
49
50       •   DEL (character 127) is displayed as ^?.
51
52       •   Values  above 128 are either meta characters (if the screen has not
53           been initialized, or if meta(3X) has been called with a TRUE param‐
54           eter),  shown  in the M-X notation, or are displayed as themselves.
55           In the latter case, the values may not be printable;  this  follows
56           the X/Open specification.
57
58       •   Values above 256 may be the names of the names of function keys.
59
60       •   Otherwise  (if there is no corresponding name) the function returns
61           null, to denote an error.  X/Open also lists an “UNKNOWN  KEY”  re‐
62           turn value, which some implementations return rather than null.
63
64       The  corresponding key_name returns a character string corresponding to
65       the wide-character value w.  The two functions do not return  the  same
66       set  of strings; the latter returns null where the former would display
67       a meta character.
68
69   filter/nofilter
70       The filter routine, if used, must be called before initscr  or  newterm
71       are called.  Calling filter causes these changes in initialization:
72
73LINES is set to 1;
74
75       •   the  capabilities  clear,  cud1,  cud, cup, cuu1, cuu, vpa are dis‐
76           abled;
77
78       •   the capability ed is disabled if bce is set;
79
80       •   and the home string is set to the value of cr.
81
82       The nofilter routine cancels the effect of  a  preceding  filter  call.
83       That  allows  the  caller to initialize a screen on a different device,
84       using a different value of $TERM.  The limitation  arises  because  the
85       filter routine modifies the in-memory copy of the terminal information.
86
87   use_env
88       The  use_env  routine,  if  used,  should  be  called before initscr or
89       newterm are called (because those compute the screen size).   It  modi‐
90       fies  the way ncurses treats environment variables when determining the
91       screen size.
92
93       •   Normally ncurses looks first  at  the  terminal  database  for  the
94           screen size.
95
96           If  use_env  was called with FALSE for parameter, it stops here un‐
97           less use_tioctl was also called with TRUE for parameter.
98
99       •   Then it asks for the screen size via operating  system  calls.   If
100           successful, it overrides the values from the terminal database.
101
102       •   Finally  (unless  use_env was called with FALSE parameter), ncurses
103           examines the LINES or COLUMNS environment variables, using a  value
104           in  those to override the results from the operating system or ter‐
105           minal database.
106
107           Ncurses also updates the screen size in response to  SIGWINCH,  un‐
108           less overridden by the LINES or COLUMNS environment variables,
109
110   use_tioctl
111       The  use_tioctl  routine,  if  used, should be called before initscr or
112       newterm are called (because those  compute  the  screen  size).   After
113       use_tioctl  is  called  with  TRUE as an argument, ncurses modifies the
114       last step in its computation of screen size as follows:
115
116       •   checks if the LINES and COLUMNS environment variables are set to  a
117           number greater than zero.
118
119       •   for  each,  ncurses  updates the corresponding environment variable
120           with the value that it has obtained via operating  system  call  or
121           from the terminal database.
122
123ncurses  re-fetches  the value of the environment variables so that
124           it is still the environment variables which set the screen size.
125
126       The use_env and use_tioctl routines combine as summarized here:
127
128           use_env   use_tioctl   Summary
129           ────────────────────────────────────────────────────────────────
130
131
132
133           TRUE      FALSE        This is the default  behavior.   ncurses
134                                  uses operating system calls unless over‐
135                                  ridden by $LINES or $COLUMNS environment
136                                  variables.
137           TRUE      TRUE         ncurses   updates  $LINES  and  $COLUMNS
138                                  based on operating system calls.
139           FALSE     TRUE         ncurses ignores $LINES and $COLUMNS, us‐
140                                  es  operating  system  calls  to  obtain
141                                  size.
142           FALSE     FALSE        ncurses relies on the terminal  database
143                                  to determine size.
144
145   putwin/getwin
146       The  putwin routine writes all data associated with window (or pad) win
147       into the file to which filep points.  This information can be later re‐
148       trieved using the getwin function.
149
150       The  getwin  routine  reads  window  related data stored in the file by
151       putwin.  The routine then creates and initializes a  new  window  using
152       that  data.   It  returns a pointer to the new window.  There are a few
153       caveats:
154
155       •   the data written is a copy of the WINDOW structure, and its associ‐
156           ated  character cells.  The format differs between the wide-charac‐
157           ter (ncursesw) and non-wide (ncurses) libraries.  You can  transfer
158           data between the two, however.
159
160       •   the  retrieved  window  is always created as a top-level window (or
161           pad), rather than a subwindow.
162
163       •   the window's character cells contain the color pair value, but  not
164           the  actual  color  numbers.   If cells in the retrieved window use
165           color pairs which have not been created in  the  application  using
166           init_pair, they will not be colored when the window is refreshed.
167
168   delay_output
169       The  delay_output  routine  inserts  an ms millisecond pause in output.
170       This routine should not be used extensively because padding  characters
171       are  used  rather  than a CPU pause.  If no padding character is speci‐
172       fied, this uses napms to perform the delay.
173
174   flushinp
175       The flushinp routine throws away any typeahead that has been  typed  by
176       the user and has not yet been read by the program.
177

RETURN VALUE

179       Except  for  flushinp,  routines that return an integer return ERR upon
180       failure and OK (SVr4 specifies only "an integer value other than  ERR")
181       upon successful completion.
182
183       Routines that return pointers return NULL on error.
184
185       X/Open does not define any error conditions.  In this implementation
186
187          flushinp
188               returns an error if the terminal was not initialized.
189
190          putwin
191               returns  an  error if the associated fwrite calls return an er‐
192               ror.
193

PORTABILITY

195   filter
196       The SVr4 documentation describes the  action  of  filter  only  in  the
197       vaguest  terms.   The  description  here is adapted from the XSI Curses
198       standard (which erroneously fails to describe the disabling of cuu).
199
200   keyname
201       The keyname function may return the names of user-defined string  capa‐
202       bilities  which  are defined in the terminfo entry via the -x option of
203       tic.  This implementation automatically assigns at run-time keycodes to
204       user-defined  strings  which  begin  with  “k”.   The keycodes start at
205       KEY_MAX, but are not guaranteed to be the same value for different runs
206       because  user-defined  codes  are merged from all terminal descriptions
207       which have been loaded.  The use_extended_names(3X)  function  controls
208       whether  this  data  is loaded when the terminal description is read by
209       the library.
210
211   nofilter/use_tioctl
212       The nofilter and use_tioctl routines are  specific  to  ncurses.   They
213       were  not  supported on Version 7, BSD or System V implementations.  It
214       is recommended that any code depending on ncurses extensions be  condi‐
215       tioned using NCURSES_VERSION.
216
217   putwin/getwin file-format
218       The putwin and getwin functions have several issues with portability:
219
220       •   The  files  written  and read by these functions use an implementa‐
221           tion-specific format.  Although the format is an obvious target for
222           standardization, it has been overlooked.
223
224           Interestingly  enough,  according to the copyright dates in Solaris
225           source, the functions (along with scr_init, etc.)  originated  with
226           the University of California, Berkeley (in 1982) and were later (in
227           1988) incorporated into SVr4.  Oddly, there are no  such  functions
228           in the 4.3BSD curses sources.
229
230       •   Most implementations simply dump the binary WINDOW structure to the
231           file.  These include SVr4 curses, NetBSD and PDCurses, as  well  as
232           older ncurses versions.  This implementation (as well as the X/Open
233           variant of Solaris curses, dated 1995) uses textual dumps.
234
235           The implementations which  use  binary  dumps  use  block-I/O  (the
236           fwrite  and  fread  functions).   Those  that use textual dumps use
237           buffered-I/O.  A few applications may happen to write extra data in
238           the  file  using these functions.  Doing that can run into problems
239           mixing block- and buffered-I/O.  This  implementation  reduces  the
240           problem  on writes by flushing the output.  However, reading from a
241           file written using mixed schemes may not be successful.
242
243   unctrl/wunctrl
244       The XSI Curses standard, Issue 4 describes these functions.  It  states
245       that unctrl and wunctrl will return a null pointer if unsuccessful, but
246       does not define any error conditions.  This implementation  checks  for
247       three cases:
248
249       •   the  parameter  is  a  7-bit  US-ASCII code.  This is the case that
250           X/Open Curses documented.
251
252       •   the parameter is in the range 128-159, i.e., a C1 control code.  If
253           use_legacy_coding(3X)  has  been  called with a 2 parameter, unctrl
254           returns the parameter, i.e., a one-character string with the param‐
255           eter  as  the  first  character.  Otherwise, it returns “~@”, “~A”,
256           etc., analogous to “^@”, “^A”, C0 controls.
257
258           X/Open Curses does not document whether unctrl can be called before
259           initializing curses.  This implementation permits that, and returns
260           the “~@”, etc., values in that case.
261
262       •   parameter values outside the 0 to 255 range.  unctrl returns a null
263           pointer.
264
265       The strings returned by unctrl in this implementation are determined at
266       compile time, showing C1 controls from the upper-128 codes with  a  “~”
267       prefix  rather  than “^”.  Other implementations have different conven‐
268       tions.  For example, they may show both sets of control characters with
269       “^”, and strip the parameter to 7 bits.  Or they may ignore C1 controls
270       and treat all of the upper-128 codes as printable.  This implementation
271       uses  8  bits  but  does  not modify the string to reflect locale.  The
272       use_legacy_coding(3X) function allows the caller to change  the  output
273       of unctrl.
274
275       Likewise,  the meta(3X) function allows the caller to change the output
276       of keyname, i.e., it determines whether to  use  the  “M-”  prefix  for
277       “meta”  keys  (codes  in  the  range 128 to 255).  Both use_legacy_cod‐
278       ing(3X) and meta(3X) succeed only after curses is initialized.   X/Open
279       Curses  does  not  document  the  treatment  of codes 128 to 159.  When
280       treating them as “meta” keys (or if keyname is called before initializ‐
281       ing curses), this implementation returns strings “M-^@”, “M-^A”, etc.
282
283       X/Open Curses documents unctrl as declared in <unctrl.h>, which ncurses
284       does.  However, ncurses' <curses.h> includes <unctrl.h>,  matching  the
285       behavior of SVr4 curses.  Other implementations may not do that.
286
287   use_env/use_tioctl
288       If  ncurses  is  configured  to provide the sp-functions extension, the
289       state of use_env and use_tioctl may be  updated  before  creating  each
290       screen  rather  than  once  only  (curs_sp_funcs(3X)).  This feature of
291       use_env is not provided by other implementation of curses.
292

SEE ALSO

294       curses(3X),   curs_initscr(3X),    curs_inopts(3X),    curs_kernel(3X),
295       curs_scr_dump(3X),  curs_sp_funcs(3X),  curs_variables(3X), legacy_cod‐
296       ing(3X).
297
298
299
300                                                                 curs_util(3X)
Impressum