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