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       char *unctrl(chtype c);
14       wchar_t *wunctrl(cchar_t *c);
15       char *keyname(int c);
16       char *key_name(wchar_t w);
17       void filter(void);
18       void nofilter(void);
19       void use_env(bool f);
20       void use_tioctl(bool f);
21       int putwin(WINDOW *win, FILE *filep);
22       WINDOW *getwin(FILE *filep);
23       int delay_output(int ms);
24       int flushinp(void);
25

DESCRIPTION

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

RETURN VALUE

169       Except  for  flushinp,  routines that return an integer return ERR upon
170       failure and OK (SVr4 specifies only "an integer value other than  ERR")
171       upon successful completion.
172
173       Routines that return pointers return NULL on error.
174
175       X/Open does not define any error conditions.  In this implementation
176
177          flushinp
178               returns an error if the terminal was not initialized.
179
180          putwin
181               returns  an  error if the associated fwrite calls return an er‐
182               ror.
183

PORTABILITY

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

SEE ALSO

280       legacy_coding(3X),   curses(3X),   curs_initscr(3X),   curs_inopts(3X),
281       curs_kernel(3X),   curs_scr_dump(3X),   curs_sp_funcs(3X),   curs_vari‐
282       ables(3X), legacy_coding(3X).
283
284
285
286                                                                 curs_util(3X)
Impressum