]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_initscr.3x
ncurses 6.2 - patch 20200321
[ncurses.git] / man / curs_initscr.3x
1 .\"***************************************************************************
2 .\" Copyright 2018,2020 Thomas E. Dickey                                     *
3 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
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 .\"
30 .\" $Id: curs_initscr.3x,v 1.32 2020/02/02 23:34:34 tom Exp $
31 .TH curs_initscr 3X ""
32 .de bP
33 .ie n  .IP \(bu 4
34 .el    .IP \(bu 2
35 ..
36 .ie \n(.g .ds `` \(lq
37 .el       .ds `` ``
38 .ie \n(.g .ds '' \(rq
39 .el       .ds '' ''
40 .na
41 .hy 0
42 .SH NAME
43 \fBinitscr\fR,
44 \fBnewterm\fR,
45 \fBendwin\fR,
46 \fBisendwin\fR,
47 \fBset_term\fR,
48 \fBdelscreen\fR \- \fBcurses\fR screen initialization and manipulation routines
49 .ad
50 .hy
51 .SH SYNOPSIS
52 \fB#include <curses.h>\fR
53 .sp
54 \fBWINDOW *initscr(void);\fR
55 .br
56 \fBint endwin(void);\fR
57 .br
58 \fBbool isendwin(void);\fR
59 .br
60 \fBSCREEN *newterm(const char *\fP\fItype\fP\fB, FILE *\fP\fIoutfd\fP\fB, FILE *\fP\fIinfd\fP\fB);\fR
61 .br
62 \fBSCREEN *set_term(SCREEN *\fP\fInew\fP\fB);\fR
63 .br
64 \fBvoid delscreen(SCREEN* \fP\fIsp\fP\fB);\fR
65 .br
66 .SH DESCRIPTION
67 .SS initscr
68 \fBinitscr\fR is normally the first \fBcurses\fR routine to call when
69 initializing a program.
70 A few special routines sometimes need to be called before it;
71 these are \fBslk_init\fR(3X), \fBfilter\fR, \fBripoffline\fR,
72 \fBuse_env\fR.
73 For multiple-terminal applications,
74 \fBnewterm\fR may be called before \fBinitscr\fR.
75 .PP
76 The initscr code determines the terminal type and initializes all \fBcurses\fR
77 data structures.
78 \fBinitscr\fR also causes the first call to \fBrefresh\fR(3X)
79 to clear the screen.
80 If errors occur, \fBinitscr\fR writes an appropriate error
81 message to standard error and exits;
82 otherwise, a pointer is returned to \fBstdscr\fR.
83 .SS newterm
84 .PP
85 A program that outputs to more than one terminal should use the \fBnewterm\fR
86 routine for each terminal instead of \fBinitscr\fR.
87 A program that needs to inspect capabilities,
88 so it can continue to run in a line-oriented mode if the
89 terminal cannot support a screen-oriented program, would also use
90 \fBnewterm\fR.
91 The routine \fBnewterm\fR should be called once for each terminal.
92 It returns a variable of type \fBSCREEN *\fR which should be saved
93 as a reference to that terminal.
94 \fBnewterm\fP's arguments are
95 .bP
96 the \fItype\fR of the terminal to be used in place of \fB$TERM\fR,
97 .bP
98 a file pointer for output to the terminal, and
99 .bP
100 another file pointer for input from the terminal
101 .PP
102 If the \fItype\fR parameter is \fBNULL\fR, \fB$TERM\fR will be used.
103 .SS endwin
104 .PP
105 The program must also call
106 \fBendwin\fR for each terminal being used before exiting from \fBcurses\fR.
107 If \fBnewterm\fR is called more than once for the same terminal, the first
108 terminal referred to must be the last one for which \fBendwin\fR is called.
109 .PP
110 A program should always call \fBendwin\fR before exiting or escaping from
111 \fBcurses\fR mode temporarily.
112 This routine
113 .bP
114 resets colors to correspond with the default color pair 0,
115 .bP
116 moves the cursor to the lower left-hand corner of the screen,
117 .bP
118 clears the remainder of the line so that it uses the default colors,
119 .bP
120 sets the cursor to normal visibility (see \fBcurs_set\fP(3X)),
121 .bP
122 stops cursor-addressing mode using the \fIexit_ca_mode\fP terminal capability,
123 .bP
124 restores tty modes (see \fBreset_shell_mode\fP(3X)).
125 .PP
126 Calling \fBrefresh\fR(3X) or \fBdoupdate\fR(3X) after a
127 temporary escape causes the program to resume visual mode.
128 .SS isendwin
129 .PP
130 The \fBisendwin\fR routine returns \fBTRUE\fR if \fBendwin\fR has been
131 called without any subsequent calls to \fBwrefresh\fR,
132 and \fBFALSE\fR otherwise.
133 .SS set_term
134 .PP
135 The \fBset_term\fR routine is used to switch between different terminals.
136 The screen reference \fBnew\fR becomes the new current terminal.
137 The previous terminal is returned by the routine.
138 This is the only routine which manipulates \fBSCREEN\fR pointers;
139 all other routines affect only the current terminal.
140 .SS delscreen
141 .PP
142 The \fBdelscreen\fR routine frees storage associated with the
143 \fBSCREEN\fR data structure.
144 The \fBendwin\fR routine does not do
145 this, so \fBdelscreen\fR should be called after \fBendwin\fR if a
146 particular \fBSCREEN\fR is no longer needed.
147 .SH RETURN VALUE
148 \fBendwin\fR returns the integer \fBERR\fR upon failure and \fBOK\fR
149 upon successful completion.
150 .PP
151 Routines that return pointers always return \fBNULL\fR on error.
152 .PP
153 X/Open defines no error conditions.
154 In this implementation
155 .bP
156 \fBendwin\fP returns an error if the terminal was not initialized.
157 .bP
158 \fBnewterm\fP
159 returns an error if it cannot allocate the data structures for the screen,
160 or for the top-level windows within the screen,
161 i.e.,
162 \fBcurscr\fP, \fBnewscr\fP, or \fBstdscr\fP.
163 .bP
164 \fBset_term\fP
165 returns no error.
166 .SH PORTABILITY
167 These functions were described in the XSI Curses standard, Issue 4.
168 As of 2015, the current document is X/Open Curses, Issue 7.
169 .SS Differences
170 X/Open specifies that portable applications must not
171 call \fBinitscr\fR more than once:
172 .bP
173 The portable way to use \fBinitscr\fP is once only,
174 using \fBrefresh\fP (see curs_refresh(3X))
175 to restore the screen after \fBendwin\fP.
176 .bP
177 This implementation allows using \fBinitscr\fP after \fBendwin\fP.
178 .PP
179 Old versions of curses, e.g., BSD 4.4, may have returned a null pointer
180 from \fBinitscr\fR when an error is detected, rather than exiting.
181 It is safe but redundant to check the return value of \fBinitscr\fR
182 in XSI Curses.
183 .SS Unset TERM Variable
184 .PP
185 If the TERM variable is missing or empty, \fBinitscr\fP uses the
186 value \*(``unknown\*('',
187 which normally corresponds to a terminal entry with the \fIgeneric\fP
188 (\fIgn\fP) capability.
189 Generic entries are detected by \fBsetupterm\fP
190 (see curs_terminfo(3X)) and cannot be used for full-screen operation.
191 Other implementations may handle a missing/empty TERM variable differently.
192 .SS Signal Handlers
193 .PP
194 Quoting from X/Open Curses, section 3.1.1:
195 .RS 5
196 .PP
197 \fICurses implementations may provide for special handling of the \fBSIGINT\fP,
198 \fBSIGQUIT\fP and \fBSIGTSTP\fP signals
199 if their disposition is \fBSIG_DFL\fP at the time
200 \fBinitscr\fP is called \fP...
201 .PP
202 \fIAny special handling for these signals may remain in effect for the
203 life of the process or until the process changes the disposition of
204 the signal.\fP
205 .PP
206 \fINone of the Curses functions are required to be safe
207 with respect to signals \fP...
208 .RE
209 .PP
210 This implementation establishes signal handlers during initialization,
211 e.g., \fBinitscr\fP or \fBnewterm\fP.
212 Applications which must handle these signals should set up the corresponding
213 handlers \fIafter\fP initializing the library:
214 .TP 5
215 .B SIGINT
216 The handler \fIattempts\fP to cleanup the screen on exit.
217 Although it \fIusually\fP works as expected, there are limitations:
218 .RS 5
219 .bP
220 Walking the \fBSCREEN\fP list is unsafe, since all list management
221 is done without any signal blocking.
222 .bP
223 On systems which have \fBREENTRANT\fP turned on, \fBset_term\fP uses
224 functions which could deadlock or misbehave in other ways.
225 .bP
226 \fBendwin\fP calls other functions, many of which use stdio or
227 other library functions which are clearly unsafe.
228 .RE
229 .TP 5
230 .B SIGTERM
231 This uses the same handler as \fBSIGINT\fP, with the same limitations.
232 It is not mentioned in X/Open Curses, but is more suitable for this
233 purpose than \fBSIGQUIT\fP (which is used in debugging).
234 .TP 5
235 .B SIGTSTP
236 This handles the \fIstop\fP signal, used in job control.
237 When resuming the process, this implementation discards pending
238 input with \fBflushinput\fP (see curs_util(3X)), and repaints the screen
239 assuming that it has been completely altered.
240 It also updates the saved terminal modes with \fBdef_shell_mode\fP
241 (see \fBcurs_kernel\fR(3X)).
242 .TP 5
243 .B SIGWINCH
244 This handles the window-size changes which were ignored in
245 the standardization efforts.
246 The handler sets a (signal-safe) variable
247 which is later tested in \fBwgetch\fP (see curs_getch(3X)).
248 If \fBkeypad\fP has been enabled for the corresponding window,
249 \fBwgetch\fP returns the key symbol \fBKEY_RESIZE\fP.
250 At the same time, \fBwgetch\fP calls \fBresizeterm\fP to adjust the
251 standard screen \fBstdscr\fP,
252 and update other data such as \fBLINES\fP and \fBCOLS\fP.
253 .SH SEE ALSO
254 \fBcurses\fR(3X),
255 \fBcurs_kernel\fR(3X),
256 \fBcurs_refresh\fR(3X),
257 \fBcurs_slk\fR(3X),
258 \fBcurs_terminfo\fR(3X),
259 \fBcurs_util\fR(3X),
260 \fBcurs_variables\fR(3X).