]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_util.3x.html
ncurses 6.2 - patch 20210619
[ncurses.git] / doc / html / man / curs_util.3x.html
1 <!--
2   * t
3   ****************************************************************************
4   * Copyright 2018-2019,2020 Thomas E. Dickey                                *
5   * Copyright 1998-2015,2017 Free Software Foundation, Inc.                  *
6   *                                                                          *
7   * Permission is hereby granted, free of charge, to any person obtaining a  *
8   * copy of this software and associated documentation files (the            *
9   * "Software"), to deal in the Software without restriction, including      *
10   * without limitation the rights to use, copy, modify, merge, publish,      *
11   * distribute, distribute with modifications, sublicense, and/or sell       *
12   * copies of the Software, and to permit persons to whom the Software is    *
13   * furnished to do so, subject to the following conditions:                 *
14   *                                                                          *
15   * The above copyright notice and this permission notice shall be included  *
16   * in all copies or substantial portions of the Software.                   *
17   *                                                                          *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
19   * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
20   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
21   * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
22   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
23   * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
24   * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
25   *                                                                          *
26   * Except as contained in this notice, the name(s) of the above copyright   *
27   * holders shall not be used in advertising or otherwise to promote the     *
28   * sale, use or other dealings in this Software without prior written       *
29   * authorization.                                                           *
30   ****************************************************************************
31   * @Id: curs_util.3x,v 1.60 2020/12/19 22:44:46 tom Exp @
32 -->
33 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
34 <HTML>
35 <HEAD>
36 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
37 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
38 <TITLE>curs_util 3X</TITLE>
39 <link rel="author" href="mailto:bug-ncurses@gnu.org">
40 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
41 </HEAD>
42 <BODY>
43 <H1 class="no-header">curs_util 3X</H1>
44 <PRE>
45 <B><A HREF="curs_util.3X.html">curs_util(3X)</A></B>                                                    <B><A HREF="curs_util.3X.html">curs_util(3X)</A></B>
46
47
48
49
50 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
51        <B>delay_output</B>, <B>filter</B>, <B>flushinp</B>, <B>getwin</B>, <B>key_name</B>, <B>keyname</B>, <B>nofilter</B>,
52        <B>putwin</B>, <B>unctrl</B>, <B>use_env</B>, <B>use_tioctl</B>, <B>wunctrl</B> - miscellaneous <B>curses</B>
53        utility routines
54
55
56 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
57        <B>#include</B> <B>&lt;curses.h&gt;</B>
58
59        <B>const</B> <B>char</B> <B>*unctrl(chtype</B> <I>c</I><B>);</B>
60        <B>wchar_t</B> <B>*wunctrl(cchar_t</B> <B>*</B><I>c</I><B>);</B>
61
62        <B>const</B> <B>char</B> <B>*keyname(int</B> <I>c</I><B>);</B>
63        <B>const</B> <B>char</B> <B>*key_name(wchar_t</B> <I>w</I><B>);</B>
64
65        <B>void</B> <B>filter(void);</B>
66        <B>void</B> <B>nofilter(void);</B>
67
68        <B>void</B> <B>use_env(bool</B> <I>f</I><B>);</B>
69        <B>void</B> <B>use_tioctl(bool</B> <I>f</I><B>);</B>
70
71        <B>int</B> <B>putwin(WINDOW</B> <B>*</B><I>win</I><B>,</B> <B>FILE</B> <B>*</B><I>filep</I><B>);</B>
72        <B>WINDOW</B> <B>*getwin(FILE</B> <B>*</B><I>filep</I><B>);</B>
73
74        <B>int</B> <B>delay_output(int</B> <I>ms</I><B>);</B>
75        <B>int</B> <B>flushinp(void);</B>
76
77
78 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
79
80 </PRE><H3><a name="h3-unctrl">unctrl</a></H3><PRE>
81        The <B>unctrl</B> routine returns a character string which is a printable rep-
82        resentation of the character <I>c</I>, ignoring attributes.   Control  charac-
83        ters  are  displayed  in the <B>^</B><I>X</I> notation.  Printing characters are dis-
84        played as is.  The corresponding <B>wunctrl</B> returns a printable  represen-
85        tation of a wide character.
86
87
88 </PRE><H3><a name="h3-keyname_key_name">keyname/key_name</a></H3><PRE>
89        The <B>keyname</B> routine returns a character string corresponding to the key
90        <I>c</I>:
91
92        <B>o</B>   Printable characters are displayed as themselves, e.g., a one-char-
93            acter string containing the key.
94
95        <B>o</B>   Control characters are displayed in the <B>^</B><I>X</I> notation.
96
97        <B>o</B>   DEL (character 127) is displayed as <B>^?</B>.
98
99        <B>o</B>   Values  above 128 are either meta characters (if the screen has not
100            been initialized, or if <B><A HREF="curs_inopts.3X.html">meta(3X)</A></B> has been called with a <B>TRUE</B> param-
101            eter),  shown  in the <B>M-</B><I>X</I> notation, or are displayed as themselves.
102            In the latter case, the values may not be printable;  this  follows
103            the X/Open specification.
104
105        <B>o</B>   Values above 256 may be the names of the names of function keys.
106
107        <B>o</B>   Otherwise  (if there is no corresponding name) the function returns
108            null, to denote an error.  X/Open also lists an "UNKNOWN  KEY"  re-
109            turn value, which some implementations return rather than null.
110
111        The  corresponding <B>key_name</B> returns a character string corresponding to
112        the wide-character value <I>w</I>.  The two functions do not return  the  same
113        set  of strings; the latter returns null where the former would display
114        a meta character.
115
116
117 </PRE><H3><a name="h3-filter_nofilter">filter/nofilter</a></H3><PRE>
118        The <B>filter</B> routine, if used, must be called before <B>initscr</B>  or  <B>newterm</B>
119        are called.  Calling <B>filter</B> causes these changes in initialization:
120
121        <B>o</B>   <B>LINES</B> is set to 1;
122
123        <B>o</B>   the  capabilities  <B>clear</B>,  <B>cud1</B>,  <B>cud</B>, <B>cup</B>, <B>cuu1</B>, <B>cuu</B>, <B>vpa</B> are dis-
124            abled;
125
126        <B>o</B>   the capability <B>ed</B> is disabled if <B>bce</B> is set;
127
128        <B>o</B>   and the <B>home</B> string is set to the value of <B>cr</B>.
129
130        The <B>nofilter</B> routine cancels the effect of  a  preceding  <B>filter</B>  call.
131        That  allows  the  caller to initialize a screen on a different device,
132        using a different value of <B>$TERM</B>.  The limitation  arises  because  the
133        <B>filter</B> routine modifies the in-memory copy of the terminal information.
134
135
136 </PRE><H3><a name="h3-use_env">use_env</a></H3><PRE>
137        The  <B>use_env</B>  routine,  if  used,  should  be  called before <B>initscr</B> or
138        <B>newterm</B> are called (because those compute the screen size).   It  modi-
139        fies  the way <B>ncurses</B> treats environment variables when determining the
140        screen size.
141
142        <B>o</B>   Normally <B>ncurses</B> looks first  at  the  terminal  database  for  the
143            screen size.
144
145            If  <B>use_env</B>  was called with <B>FALSE</B> for parameter, it stops here un-
146            less <B>use_tioctl</B> was also called with <B>TRUE</B> for parameter.
147
148        <B>o</B>   Then it asks for the screen size via operating  system  calls.   If
149            successful, it overrides the values from the terminal database.
150
151        <B>o</B>   Finally  (unless  <B>use_env</B> was called with <B>FALSE</B> parameter), <B>ncurses</B>
152            examines the <B>LINES</B> or <B>COLUMNS</B> environment variables, using a  value
153            in  those to override the results from the operating system or ter-
154            minal database.
155
156            <B>Ncurses</B> also updates the screen size in response to  <B>SIGWINCH</B>,  un-
157            less overridden by the <B>LINES</B> or <B>COLUMNS</B> environment variables,
158
159
160 </PRE><H3><a name="h3-use_tioctl">use_tioctl</a></H3><PRE>
161        The  <B>use_tioctl</B>  routine,  if  used, should be called before <B>initscr</B> or
162        <B>newterm</B> are called (because those  compute  the  screen  size).   After
163        <B>use_tioctl</B>  is  called  with  <B>TRUE</B> as an argument, <B>ncurses</B> modifies the
164        last step in its computation of screen size as follows:
165
166        <B>o</B>   checks if the <B>LINES</B> and <B>COLUMNS</B> environment variables are set to  a
167            number greater than zero.
168
169        <B>o</B>   for  each,  <B>ncurses</B>  updates the corresponding environment variable
170            with the value that it has obtained via operating  system  call  or
171            from the terminal database.
172
173        <B>o</B>   <B>ncurses</B>  re-fetches  the value of the environment variables so that
174            it is still the environment variables which set the screen size.
175
176        The <B>use_env</B> and <B>use_tioctl</B> routines combine as summarized here:
177
178            <I>use</I><B>_</B><I>env</I>   <I>use</I><B>_</B><I>tioctl</I>   <I>Summary</I>
179            ----------------------------------------------------------------
180            TRUE      FALSE        This is the default  behavior.   <B>ncurses</B>
181                                   uses operating system calls unless over-
182                                   ridden by $LINES or $COLUMNS environment
183                                   variables.
184
185            TRUE      TRUE         <B>ncurses</B>   updates  $LINES  and  $COLUMNS
186                                   based on operating system calls.
187            FALSE     TRUE         <B>ncurses</B> ignores $LINES and $COLUMNS, us-
188                                   es  operating  system  calls  to  obtain
189                                   size.
190            FALSE     FALSE        <B>ncurses</B> relies on the terminal  database
191                                   to determine size.
192
193
194 </PRE><H3><a name="h3-putwin_getwin">putwin/getwin</a></H3><PRE>
195        The  <B>putwin</B> routine writes all data associated with window (or pad) <I>win</I>
196        into the file to which <I>filep</I> points.  This information can be later re-
197        trieved using the <B>getwin</B> function.
198
199        The  <B>getwin</B>  routine  reads  window  related data stored in the file by
200        <B>putwin</B>.  The routine then creates and initializes a  new  window  using
201        that  data.   It  returns a pointer to the new window.  There are a few
202        caveats:
203
204        <B>o</B>   the data written is a copy of the <B>WINDOW</B> structure, and its associ-
205            ated  character cells.  The format differs between the wide-charac-
206            ter (<B>ncursesw</B>) and non-wide (<B>ncurses</B>) libraries.  You can  transfer
207            data between the two, however.
208
209        <B>o</B>   the  retrieved  window  is always created as a top-level window (or
210            pad), rather than a subwindow.
211
212        <B>o</B>   the window's character cells contain the color pair <I>value</I>, but  not
213            the  actual  color  <I>numbers</I>.   If cells in the retrieved window use
214            color pairs which have not been created in  the  application  using
215            <B>init_pair</B>, they will not be colored when the window is refreshed.
216
217
218 </PRE><H3><a name="h3-delay_output">delay_output</a></H3><PRE>
219        The  <B>delay_output</B>  routine  inserts  an <I>ms</I> millisecond pause in output.
220        This routine should not be used extensively because padding  characters
221        are  used  rather  than a CPU pause.  If no padding character is speci-
222        fied, this uses <B>napms</B> to perform the delay.
223
224
225 </PRE><H3><a name="h3-flushinp">flushinp</a></H3><PRE>
226        The <B>flushinp</B> routine throws away any typeahead that has been  typed  by
227        the user and has not yet been read by the program.
228
229
230 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
231        Except  for  <B>flushinp</B>,  routines that return an integer return <B>ERR</B> upon
232        failure and <B>OK</B> (SVr4 specifies only "an integer value other than  <B>ERR</B>")
233        upon successful completion.
234
235        Routines that return pointers return <B>NULL</B> on error.
236
237        X/Open does not define any error conditions.  In this implementation
238
239           <B>flushinp</B>
240                returns an error if the terminal was not initialized.
241
242           <B>putwin</B>
243                returns  an  error if the associated <B>fwrite</B> calls return an er-
244                ror.
245
246
247 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
248
249 </PRE><H3><a name="h3-filter">filter</a></H3><PRE>
250        The SVr4 documentation describes the  action  of  <B>filter</B>  only  in  the
251        vaguest  terms.   The  description  here is adapted from the XSI Curses
252        standard (which erroneously fails to describe the disabling of <B>cuu</B>).
253
254
255 </PRE><H3><a name="h3-keyname">keyname</a></H3><PRE>
256        The <B>keyname</B> function may return the names of user-defined string  capa-
257        bilities  which  are defined in the terminfo entry via the <B>-x</B> option of
258        <B>tic</B>.  This implementation automatically assigns at run-time keycodes to
259        user-defined  strings  which  begin  with  "k".   The keycodes start at
260        KEY_MAX, but are not guaranteed to be the same value for different runs
261        because  user-defined  codes  are merged from all terminal descriptions
262        which have been loaded.  The <B><A HREF="curs_extend.3X.html">use_extended_names(3X)</A></B>  function  controls
263        whether  this  data  is loaded when the terminal description is read by
264        the library.
265
266
267 </PRE><H3><a name="h3-nofilter_use_tioctl">nofilter/use_tioctl</a></H3><PRE>
268        The <B>nofilter</B> and <B>use_tioctl</B> routines are  specific  to  <B>ncurses</B>.   They
269        were  not  supported on Version 7, BSD or System V implementations.  It
270        is recommended that any code depending on <B>ncurses</B> extensions be  condi-
271        tioned using NCURSES_VERSION.
272
273
274 </PRE><H3><a name="h3-putwin_getwin">putwin/getwin</a></H3><PRE>
275        The <B>putwin</B> and <B>getwin</B> functions have several issues with portability:
276
277        <B>o</B>   The  files  written  and read by these functions use an implementa-
278            tion-specific format.  Although the format is an obvious target for
279            standardization, it has been overlooked.
280
281            Interestingly  enough,  according to the copyright dates in Solaris
282            source, the functions (along with <B>scr_init</B>, etc.)  originated  with
283            the University of California, Berkeley (in 1982) and were later (in
284            1988) incorporated into SVr4.  Oddly, there are no  such  functions
285            in the 4.3BSD curses sources.
286
287        <B>o</B>   Most implementations simply dump the binary <B>WINDOW</B> structure to the
288            file.  These include SVr4 curses, NetBSD and PDCurses, as  well  as
289            older <B>ncurses</B> versions.  This implementation (as well as the X/Open
290            variant of Solaris curses, dated 1995) uses textual dumps.
291
292            The implementations which  use  binary  dumps  use  block-I/O  (the
293            <B>fwrite</B>  and  <B>fread</B>  functions).   Those  that use textual dumps use
294            buffered-I/O.  A few applications may happen to write extra data in
295            the  file  using these functions.  Doing that can run into problems
296            mixing block- and buffered-I/O.  This  implementation  reduces  the
297            problem  on writes by flushing the output.  However, reading from a
298            file written using mixed schemes may not be successful.
299
300
301 </PRE><H3><a name="h3-unctrl_wunctrl">unctrl/wunctrl</a></H3><PRE>
302        The XSI Curses standard, Issue 4 describes these functions.  It  states
303        that <B>unctrl</B> and <B>wunctrl</B> will return a null pointer if unsuccessful, but
304        does not define any error conditions.  This implementation  checks  for
305        three cases:
306
307        <B>o</B>   the  parameter  is  a  7-bit  US-ASCII code.  This is the case that
308            X/Open Curses documented.
309
310        <B>o</B>   the parameter is in the range 128-159, i.e., a C1 control code.  If
311            <B><A HREF="legacy_coding.3X.html">use_legacy_coding(3X)</A></B>  has  been  called with a <B>2</B> parameter, <B>unctrl</B>
312            returns the parameter, i.e., a one-character string with the param-
313            eter  as  the  first  character.  Otherwise, it returns "~@", "~A",
314            etc., analogous to "^@", "^A", C0 controls.
315
316            X/Open Curses does not document whether <B>unctrl</B> can be called before
317            initializing curses.  This implementation permits that, and returns
318            the "~@", etc., values in that case.
319
320        <B>o</B>   parameter values outside the 0 to 255 range.  <B>unctrl</B> returns a null
321            pointer.
322
323        The strings returned by <B>unctrl</B> in this implementation are determined at
324        compile time, showing C1 controls from the upper-128 codes with  a  "~"
325        prefix  rather  than "^".  Other implementations have different conven-
326        tions.  For example, they may show both sets of control characters with
327        "^", and strip the parameter to 7 bits.  Or they may ignore C1 controls
328        and treat all of the upper-128 codes as printable.  This implementation
329        uses  8  bits  but  does  not modify the string to reflect locale.  The
330        <B><A HREF="legacy_coding.3X.html">use_legacy_coding(3X)</A></B> function allows the caller to change  the  output
331        of <B>unctrl</B>.
332
333        Likewise,  the <B><A HREF="curs_inopts.3X.html">meta(3X)</A></B> function allows the caller to change the output
334        of <B>keyname</B>, i.e., it determines whether to  use  the  "M-"  prefix  for
335        "meta"  keys  (codes  in  the  range 128 to 255).  Both <B>use_legacy_cod-</B>
336        <B><A HREF="use_legacy_coding.3X.html">ing(3X)</A></B> and <B><A HREF="curs_inopts.3X.html">meta(3X)</A></B> succeed only after curses is initialized.   X/Open
337        Curses  does  not  document  the  treatment  of codes 128 to 159.  When
338        treating them as "meta" keys (or if <B>keyname</B> is called before initializ-
339        ing curses), this implementation returns strings "M-^@", "M-^A", etc.
340
341        X/Open Curses documents <B>unctrl</B> as declared in <B>&lt;unctrl.h&gt;</B>, which <B>ncurses</B>
342        does.  However, <B>ncurses</B>' <B>&lt;curses.h&gt;</B> includes <B>&lt;unctrl.h&gt;</B>,  matching  the
343        behavior of SVr4 curses.  Other implementations may not do that.
344
345
346 </PRE><H3><a name="h3-use_env_use_tioctl">use_env/use_tioctl</a></H3><PRE>
347        If  <B>ncurses</B>  is  configured  to provide the sp-functions extension, the
348        state of <B>use_env</B> and <B>use_tioctl</B> may be  updated  before  creating  each
349        <I>screen</I>  rather  than  once  only  (<B><A HREF="curs_sp_funcs.3X.html">curs_sp_funcs(3X)</A></B>).  This feature of
350        <B>use_env</B> is not provided by other implementation of curses.
351
352
353 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
354        <B><A HREF="curses.3X.html">curses(3X)</A></B>,   <B><A HREF="curs_initscr.3X.html">curs_initscr(3X)</A></B>,    <B><A HREF="curs_inopts.3X.html">curs_inopts(3X)</A></B>,    <B><A HREF="curs_kernel.3X.html">curs_kernel(3X)</A></B>,
355        <B><A HREF="curs_scr_dump.3X.html">curs_scr_dump(3X)</A></B>,  <B><A HREF="curs_sp_funcs.3X.html">curs_sp_funcs(3X)</A></B>,  <B><A HREF="curs_variables.3X.html">curs_variables(3X)</A></B>, <B>legacy_cod-</B>
356        <B><A HREF="legacy_coding.3X.html">ing(3X)</A></B>.
357
358
359
360                                                                  <B><A HREF="curs_util.3X.html">curs_util(3X)</A></B>
361 </PRE>
362 <div class="nav">
363 <ul>
364 <li><a href="#h2-NAME">NAME</a></li>
365 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
366 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
367 <ul>
368 <li><a href="#h3-unctrl">unctrl</a></li>
369 <li><a href="#h3-keyname_key_name">keyname/key_name</a></li>
370 <li><a href="#h3-filter_nofilter">filter/nofilter</a></li>
371 <li><a href="#h3-use_env">use_env</a></li>
372 <li><a href="#h3-use_tioctl">use_tioctl</a></li>
373 <li><a href="#h3-putwin_getwin">putwin/getwin</a></li>
374 <li><a href="#h3-delay_output">delay_output</a></li>
375 <li><a href="#h3-flushinp">flushinp</a></li>
376 </ul>
377 </li>
378 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
379 <li><a href="#h2-PORTABILITY">PORTABILITY</a>
380 <ul>
381 <li><a href="#h3-filter">filter</a></li>
382 <li><a href="#h3-keyname">keyname</a></li>
383 <li><a href="#h3-nofilter_use_tioctl">nofilter/use_tioctl</a></li>
384 <li><a href="#h3-putwin_getwin">putwin/getwin</a></li>
385 <li><a href="#h3-unctrl_wunctrl">unctrl/wunctrl</a></li>
386 <li><a href="#h3-use_env_use_tioctl">use_env/use_tioctl</a></li>
387 </ul>
388 </li>
389 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
390 </ul>
391 </div>
392 </BODY>
393 </HTML>