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