2 ****************************************************************************
3 * Copyright 2018,2020 Thomas E. Dickey *
4 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
29 ****************************************************************************
30 * @Id: curs_initscr.3x,v 1.33 2020/10/17 23:20:48 tom Exp @
32 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
35 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
36 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
37 <TITLE>curs_initscr 3X</TITLE>
38 <link rel="author" href="mailto:bug-ncurses@gnu.org">
39 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
42 <H1 class="no-header">curs_initscr 3X</H1>
44 <B><A HREF="curs_initscr.3X.html">curs_initscr(3X)</A></B> <B><A HREF="curs_initscr.3X.html">curs_initscr(3X)</A></B>
49 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
50 <B>initscr</B>, <B>newterm</B>, <B>endwin</B>, <B>isendwin</B>, <B>set_term</B>, <B>delscreen</B> - <B>curses</B> screen
51 initialization and manipulation routines
54 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
55 <B>#include</B> <B><curses.h></B>
57 <B>WINDOW</B> <B>*initscr(void);</B>
58 <B>int</B> <B>endwin(void);</B>
60 <B>bool</B> <B>isendwin(void);</B>
62 <B>SCREEN</B> <B>*newterm(const</B> <B>char</B> <B>*</B><I>type</I><B>,</B> <B>FILE</B> <B>*</B><I>outfd</I><B>,</B> <B>FILE</B> <B>*</B><I>infd</I><B>);</B>
63 <B>SCREEN</B> <B>*set_term(SCREEN</B> <B>*</B><I>new</I><B>);</B>
64 <B>void</B> <B>delscreen(SCREEN*</B> <I>sp</I><B>);</B>
67 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
69 </PRE><H3><a name="h3-initscr">initscr</a></H3><PRE>
70 <B>initscr</B> is normally the first <B>curses</B> routine to call when initializing
71 a program. A few special routines sometimes need to be called before
72 it; these are <B><A HREF="curs_slk.3X.html">slk_init(3X)</A></B>, <B>filter</B>, <B>ripoffline</B>, <B>use_env</B>. For multiple-
73 terminal applications, <B>newterm</B> may be called before <B>initscr</B>.
75 The initscr code determines the terminal type and initializes all <B>curs-</B>
76 <B>es</B> data structures. <B>initscr</B> also causes the first call to <B><A HREF="curscurs_refresh.3X.html">refresh(3X)</A></B>
77 to clear the screen. If errors occur, <B>initscr</B> writes an appropriate
78 error message to standard error and exits; otherwise, a pointer is re-
79 turned to <B>stdscr</B>.
82 </PRE><H3><a name="h3-newterm">newterm</a></H3><PRE>
83 A program that outputs to more than one terminal should use the <B>newterm</B>
84 routine for each terminal instead of <B>initscr</B>. A program that needs to
85 inspect capabilities, so it can continue to run in a line-oriented mode
86 if the terminal cannot support a screen-oriented program, would also
87 use <B>newterm</B>. The routine <B>newterm</B> should be called once for each termi-
88 nal. It returns a variable of type <B>SCREEN</B> <B>*</B> which should be saved as a
89 reference to that terminal. <B>newterm</B>'s arguments are
91 <B>o</B> the <I>type</I> of the terminal to be used in place of <B>$TERM</B>,
93 <B>o</B> a file pointer for output to the terminal, and
95 <B>o</B> another file pointer for input from the terminal
97 If the <I>type</I> parameter is <B>NULL</B>, <B>$TERM</B> will be used.
100 </PRE><H3><a name="h3-endwin">endwin</a></H3><PRE>
101 The program must also call <B>endwin</B> for each terminal being used before
102 exiting from <B>curses</B>. If <B>newterm</B> is called more than once for the same
103 terminal, the first terminal referred to must be the last one for which
104 <B>endwin</B> is called.
106 A program should always call <B>endwin</B> before exiting or escaping from
107 <B>curses</B> mode temporarily. This routine
109 <B>o</B> resets colors to correspond with the default color pair 0,
111 <B>o</B> moves the cursor to the lower left-hand corner of the screen,
113 <B>o</B> clears the remainder of the line so that it uses the default col-
116 <B>o</B> sets the cursor to normal visibility (see <B><A HREF="curs_kernel.3X.html">curs_set(3X)</A></B>),
118 <B>o</B> stops cursor-addressing mode using the <I>exit</I><B>_</B><I>ca</I><B>_</B><I>mode</I> terminal capa-
121 <B>o</B> restores tty modes (see <B><A HREF="curs_kernel.3X.html">reset_shell_mode(3X)</A></B>).
123 Calling <B><A HREF="curs_refresh.3X.html">refresh(3X)</A></B> or <B><A HREF="curs_refresh.3X.html">doupdate(3X)</A></B> after a temporary escape causes the
124 program to resume visual mode.
127 </PRE><H3><a name="h3-isendwin">isendwin</a></H3><PRE>
128 The <B>isendwin</B> routine returns <B>TRUE</B> if <B>endwin</B> has been called without any
129 subsequent calls to <B>wrefresh</B>, and <B>FALSE</B> otherwise.
132 </PRE><H3><a name="h3-set_term">set_term</a></H3><PRE>
133 The <B>set_term</B> routine is used to switch between different terminals.
134 The screen reference <B>new</B> becomes the new current terminal. The previ-
135 ous terminal is returned by the routine. This is the only routine
136 which manipulates <B>SCREEN</B> pointers; all other routines affect only the
140 </PRE><H3><a name="h3-delscreen">delscreen</a></H3><PRE>
141 The <B>delscreen</B> routine frees storage associated with the <B>SCREEN</B> data
142 structure. The <B>endwin</B> routine does not do this, so <B>delscreen</B> should be
143 called after <B>endwin</B> if a particular <B>SCREEN</B> is no longer needed.
146 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
147 <B>endwin</B> returns the integer <B>ERR</B> upon failure and <B>OK</B> upon successful com-
150 Routines that return pointers always return <B>NULL</B> on error.
152 X/Open defines no error conditions. In this implementation
154 <B>o</B> <B>endwin</B> returns an error if the terminal was not initialized.
156 <B>o</B> <B>newterm</B> returns an error if it cannot allocate the data structures
157 for the screen, or for the top-level windows within the screen,
158 i.e., <B>curscr</B>, <B>newscr</B>, or <B>stdscr</B>.
160 <B>o</B> <B>set_term</B> returns no error.
163 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
164 These functions were described in the XSI Curses standard, Issue 4. As
165 of 2015, the current document is X/Open Curses, Issue 7.
168 </PRE><H3><a name="h3-Differences">Differences</a></H3><PRE>
169 X/Open specifies that portable applications must not call <B>initscr</B> more
172 <B>o</B> The portable way to use <B>initscr</B> is once only, using <B>refresh</B> (see
173 <B><A HREF="curs_refresh.3X.html">curs_refresh(3X)</A></B>) to restore the screen after <B>endwin</B>.
175 <B>o</B> This implementation allows using <B>initscr</B> after <B>endwin</B>.
177 Old versions of curses, e.g., BSD 4.4, may have returned a null pointer
178 from <B>initscr</B> when an error is detected, rather than exiting. It is
179 safe but redundant to check the return value of <B>initscr</B> in XSI Curses.
182 </PRE><H3><a name="h3-Unset-TERM-Variable">Unset TERM Variable</a></H3><PRE>
183 If the TERM variable is missing or empty, <B>initscr</B> uses the value "un-
184 known", which normally corresponds to a terminal entry with the <I>generic</I>
185 (<I>gn</I>) capability. Generic entries are detected by <B>setupterm</B> (see
186 <B><A HREF="curs_terminfo.3X.html">curs_terminfo(3X)</A></B>) and cannot be used for full-screen operation. Other
187 implementations may handle a missing/empty TERM variable differently.
190 </PRE><H3><a name="h3-Signal-Handlers">Signal Handlers</a></H3><PRE>
191 Quoting from X/Open Curses, section 3.1.1:
193 <I>Curses</I> <I>implementations</I> <I>may</I> <I>provide</I> <I>for</I> <I>special</I> <I>handling</I> <I>of</I> <I>the</I>
194 <B>SIGINT</B><I>,</I> <B>SIGQUIT</B> <I>and</I> <B>SIGTSTP</B> <I>signals</I> <I>if</I> <I>their</I> <I>disposition</I> <I>is</I>
195 <B>SIG_DFL</B> <I>at</I> <I>the</I> <I>time</I> <B>initscr</B> <I>is</I> <I>called</I> <B>...</B>
197 <I>Any</I> <I>special</I> <I>handling</I> <I>for</I> <I>these</I> <I>signals</I> <I>may</I> <I>remain</I> <I>in</I> <I>effect</I> <I>for</I>
198 <I>the</I> <I>life</I> <I>of</I> <I>the</I> <I>process</I> <I>or</I> <I>until</I> <I>the</I> <I>process</I> <I>changes</I> <I>the</I> <I>disposi-</I>
199 <I>tion</I> <I>of</I> <I>the</I> <I>signal.</I>
201 <I>None</I> <I>of</I> <I>the</I> <I>Curses</I> <I>functions</I> <I>are</I> <I>required</I> <I>to</I> <I>be</I> <I>safe</I> <I>with</I> <I>respect</I>
202 <I>to</I> <I>signals</I> ...
204 This implementation establishes signal handlers during initialization,
205 e.g., <B>initscr</B> or <B>newterm</B>. Applications which must handle these signals
206 should set up the corresponding handlers <I>after</I> initializing the li-
210 The handler <I>attempts</I> to cleanup the screen on exit. Although it
211 <I>usually</I> works as expected, there are limitations:
213 <B>o</B> Walking the <B>SCREEN</B> list is unsafe, since all list management
214 is done without any signal blocking.
216 <B>o</B> On systems which have <B>REENTRANT</B> turned on, <B>set_term</B> uses func-
217 tions which could deadlock or misbehave in other ways.
219 <B>o</B> <B>endwin</B> calls other functions, many of which use stdio or other
220 library functions which are clearly unsafe.
223 This uses the same handler as <B>SIGINT</B>, with the same limitations.
224 It is not mentioned in X/Open Curses, but is more suitable for
225 this purpose than <B>SIGQUIT</B> (which is used in debugging).
228 This handles the <I>stop</I> signal, used in job control. When resuming
229 the process, this implementation discards pending input with
230 <B>flushinput</B> (see <B><A HREF="curs_util.3X.html">curs_util(3X)</A></B>), and repaints the screen assuming
231 that it has been completely altered. It also updates the saved
232 terminal modes with <B>def_shell_mode</B> (see <B><A HREF="curs_kernel.3X.html">curs_kernel(3X)</A></B>).
235 This handles the window-size changes which were ignored in the
236 standardization efforts. The handler sets a (signal-safe) vari-
237 able which is later tested in <B>wgetch</B> (see <B><A HREF="curs_getch.3X.html">curs_getch(3X)</A></B>). If
238 <B>keypad</B> has been enabled for the corresponding window, <B>wgetch</B> re-
239 turns the key symbol <B>KEY_RESIZE</B>. At the same time, <B>wgetch</B> calls
240 <B>resizeterm</B> to adjust the standard screen <B>stdscr</B>, and update other
241 data such as <B>LINES</B> and <B>COLS</B>.
244 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
245 <B><A HREF="curses.3X.html">curses(3X)</A></B>, <B><A HREF="curs_kernel.3X.html">curs_kernel(3X)</A></B>, <B><A HREF="curs_refresh.3X.html">curs_refresh(3X)</A></B>, <B><A HREF="curs_slk.3X.html">curs_slk(3X)</A></B>, <B>curs_ter-</B>
246 <B><A HREF="curs_terminfo.3X.html">minfo(3X)</A></B>, <B><A HREF="curs_util.3X.html">curs_util(3X)</A></B>, <B><A HREF="curs_variables.3X.html">curs_variables(3X)</A></B>.
250 <B><A HREF="curs_initscr.3X.html">curs_initscr(3X)</A></B>
254 <li><a href="#h2-NAME">NAME</a></li>
255 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
256 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
258 <li><a href="#h3-initscr">initscr</a></li>
259 <li><a href="#h3-newterm">newterm</a></li>
260 <li><a href="#h3-endwin">endwin</a></li>
261 <li><a href="#h3-isendwin">isendwin</a></li>
262 <li><a href="#h3-set_term">set_term</a></li>
263 <li><a href="#h3-delscreen">delscreen</a></li>
266 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
267 <li><a href="#h2-PORTABILITY">PORTABILITY</a>
269 <li><a href="#h3-Differences">Differences</a></li>
270 <li><a href="#h3-Unset-TERM-Variable">Unset TERM Variable</a></li>
271 <li><a href="#h3-Signal-Handlers">Signal Handlers</a></li>
274 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>