blob: dc15ecbca87bd20467d4588e51b37a64e7c8c481 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301.\"***************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +01002.\" Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05303.\" *
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.\"
Steve Kondikae271bc2015-11-15 02:50:53 +010029.\" $Id: curs_initscr.3x,v 1.24 2015/07/21 23:01:38 tom Exp $
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053030.TH curs_initscr 3X ""
Steve Kondikae271bc2015-11-15 02:50:53 +010031.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 '' ''
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053038.na
39.hy 0
40.SH NAME
41\fBinitscr\fR,
42\fBnewterm\fR,
43\fBendwin\fR,
44\fBisendwin\fR,
45\fBset_term\fR,
Steve Kondikae271bc2015-11-15 02:50:53 +010046\fBdelscreen\fR \- \fBcurses\fR screen initialization and manipulation routines
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047.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
Steve Kondikae271bc2015-11-15 02:50:53 +010058\fBSCREEN *newterm(char *\fP\fItype\fP\fB, FILE *\fP\fIoutfd\fP\fB, FILE *\fP\fIinfd\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053059.br
Steve Kondikae271bc2015-11-15 02:50:53 +010060\fBSCREEN *set_term(SCREEN *\fP\fInew\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053061.br
Steve Kondikae271bc2015-11-15 02:50:53 +010062\fBvoid delscreen(SCREEN* \fP\fIsp\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053063.br
64.SH DESCRIPTION
Steve Kondikae271bc2015-11-15 02:50:53 +010065.SS initscr
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053066\fBinitscr\fR is normally the first \fBcurses\fR routine to call when
Steve Kondikae271bc2015-11-15 02:50:53 +010067initializing a program.
68A few special routines sometimes need to be called before it;
69these are \fBslk_init\fR, \fBfilter\fR, \fBripoffline\fR,
70\fBuse_env\fR.
71For multiple-terminal applications,
72\fBnewterm\fR may be called before \fBinitscr\fR.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053073.PP
74The initscr code determines the terminal type and initializes all \fBcurses\fR
Steve Kondikae271bc2015-11-15 02:50:53 +010075data structures.
76\fBinitscr\fR also causes the first call to \fBrefresh\fR to clear the screen.
77If errors occur, \fBinitscr\fR writes an appropriate error
78message to standard error and exits;
79otherwise, a pointer is returned to \fBstdscr\fR.
80.SS newterm
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053081.PP
82A program that outputs to more than one terminal should use the \fBnewterm\fR
Steve Kondikae271bc2015-11-15 02:50:53 +010083routine for each terminal instead of \fBinitscr\fR.
84A program that needs to inspect capabilities,
85so it can continue to run in a line-oriented mode if the
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053086terminal cannot support a screen-oriented program, would also use
Steve Kondikae271bc2015-11-15 02:50:53 +010087\fBnewterm\fR.
88The routine \fBnewterm\fR should be called once for each terminal.
89It returns a variable of type \fBSCREEN *\fR which should be saved
90as a reference to that terminal.
91\fBnewterm\fP's arguments are
92.bP
93the \fItype\fR of the terminal to be used in place of \fB$TERM\fR,
94.bP
95a file pointer for output to the terminal, and
96.bP
97another file pointer for input from the terminal
98.PP
99If the \fItype\fR parameter is \fBNULL\fR, \fB$TERM\fR will be used.
100.SS endwin
101.PP
102The program must also call
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530103\fBendwin\fR for each terminal being used before exiting from \fBcurses\fR.
104If \fBnewterm\fR is called more than once for the same terminal, the first
105terminal referred to must be the last one for which \fBendwin\fR is called.
106.PP
107A program should always call \fBendwin\fR before exiting or escaping from
Steve Kondikae271bc2015-11-15 02:50:53 +0100108\fBcurses\fR mode temporarily.
109This routine
110.bP
111restores tty modes,
112.bP
113moves the cursor to the lower left-hand corner of the screen and
114.bP
115resets the terminal into
116the proper non-visual mode.
117.PP
118Calling \fBrefresh\fR or \fBdoupdate\fR after a
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530119temporary escape causes the program to resume visual mode.
Steve Kondikae271bc2015-11-15 02:50:53 +0100120.SS isendwin
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530121.PP
122The \fBisendwin\fR routine returns \fBTRUE\fR if \fBendwin\fR has been
Steve Kondikae271bc2015-11-15 02:50:53 +0100123called without any subsequent calls to \fBwrefresh\fR,
124and \fBFALSE\fR otherwise.
125.SS set_term
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530126.PP
Steve Kondikae271bc2015-11-15 02:50:53 +0100127The \fBset_term\fR routine is used to switch between different terminals.
128The screen reference \fBnew\fR becomes the new current terminal.
129The previous terminal is returned by the routine.
130This is the only routine which manipulates \fBSCREEN\fR pointers;
131all other routines affect only the current terminal.
132.SS delscreen
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530133.PP
134The \fBdelscreen\fR routine frees storage associated with the
Steve Kondikae271bc2015-11-15 02:50:53 +0100135\fBSCREEN\fR data structure.
136The \fBendwin\fR routine does not do
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530137this, so \fBdelscreen\fR should be called after \fBendwin\fR if a
138particular \fBSCREEN\fR is no longer needed.
139.SH RETURN VALUE
140\fBendwin\fR returns the integer \fBERR\fR upon failure and \fBOK\fR
141upon successful completion.
142.PP
143Routines that return pointers always return \fBNULL\fR on error.
144.PP
145X/Open defines no error conditions.
146In this implementation
Steve Kondikae271bc2015-11-15 02:50:53 +0100147.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530148\fBendwin\fP returns an error if the terminal was not initialized.
Steve Kondikae271bc2015-11-15 02:50:53 +0100149.bP
150\fBnewterm\fP
151returns an error if it cannot allocate the data structures for the screen,
152or for the top-level windows within the screen,
153i.e.,
154\fBcurscr\fP, \fBnewscr\fP, or \fBstdscr\fP.
155.bP
156\fBset_term\fP
157returns no error.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530158.SH NOTES
159Note that \fBinitscr\fR and \fBnewterm\fR may be macros.
160.SH PORTABILITY
Steve Kondikae271bc2015-11-15 02:50:53 +0100161These functions were described in the XSI Curses standard, Issue 4.
162As of 2015, the current document is X/Open Curses, Issue 7.
163.SS Differences
164X/Open specifies that portable applications must not
165call \fBinitscr\fR more than once:
166.bP
167The portable way to use \fBinitscr\fP is once only,
168using \fBrefresh\fP (see curs_refresh(3X)) to restore the screen after \fBendwin\fP.
169.bP
170This implementation allows using \fBinitscr\fP after \fBendwin\fP.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530171.PP
172Old versions of curses, e.g., BSD 4.4, may have returned a null pointer
173from \fBinitscr\fR when an error is detected, rather than exiting.
174It is safe but redundant to check the return value of \fBinitscr\fR
175in XSI Curses.
Steve Kondikae271bc2015-11-15 02:50:53 +0100176.SS Unset TERM Variable
177.PP
178If the TERM variable is missing or empty, \fBinitscr\fP uses the
179value \*(``unknown\*('',
180which normally corresponds to a terminal entry with the \fIgeneric\fP
181(\fIgn\fP) capability.
182Generic entries are detected by \fBsetupterm\fP (see curs_terminfo(3X)) and cannot be
183used for full-screen operation.
184Other implementations may handle a missing/empty TERM variable differently.
185.SS Signal Handlers
186.PP
187Quoting from X/Open Curses, section 3.1.1:
188.RS 5
189.PP
190\fICurses implementations may provide for special handling of the SIGINT,
191SIGQUIT and SIGTSTP signals if their disposition is SIG_DFL at the time
192\fBinitscr()\fP is called \fP...
193.PP
194\fIAny special handling for these signals may remain in effect for the
195life of the process or until the process changes the disposition of
196the signal.\fP
197.PP
198\fINone of the Curses functions are required to be safe with respect to signals \fP...
199.RE
200.PP
201This implementation establishes signal handlers during initialization,
202e.g., \fBinitscr\fP or \fBnewterm\fP.
203Applications which must handle these signals should set up the corresponding
204handlers \fIafter\fP initializing the library:
205.TP 5
206.B SIGINT
207The handler \fIattempts\fP to cleanup the screen on exit.
208Although it \fIusually\fP works as expected, there are limitations:
209.RS 5
210.bP
211Walking the \fBSCREEN\fP list is unsafe, since all list management
212is done without any signal blocking.
213.bP
214On systems which have \fBREENTRANT\fP turned on, \fBset_term\fP uses
215functions which could deadlock or misbehave in other ways.
216.bP
217\fBendwin\fP calls other functions, many of which use stdio or
218other library functions which are clearly unsafe.
219.RE
220.TP 5
221.B SIGTERM
222This uses the same handler as \fBSIGINT\fP, with the same limitations.
223It is not mentioned in X/Open Curses, but is more suitable for this
224purpose than \fBSIGQUIT\fP (which is used in debugging).
225.TP 5
226.B SIGTSTP
227This handles the \fIstop\fP signal, used in job control.
228When resuming the process, this implementation discards pending
229input with \fBflushinput\fP (see curs_util(3X)), and repaints the screen
230assuming that it has been completely altered.
231It also updates the saved terminal modes with \fBdef_shell_mode\fP (see curs_kernel(3X)).
232.TP 5
233.B SIGWINCH
234This handles the window-size changes which were initially ignored in
235the standardization efforts.
236The handler sets a (signal-safe) variable
237which is later tested in \fBwgetch\fP (see curs_getch(3X)).
238If \fBkeypad\fP has been enabled for the corresponding window,
239\fBwgetch\fP returns the key symbol \fBKEY_RESIZE\fP.
240At the same time, \fBwgetch\fP calls \fBresizeterm\fP to adjust the
241standard screen \fBstdscr\fP,
242and update other data such as \fBLINES\fP and \fBCOLS\fP.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530243.SH SEE ALSO
Steve Kondikae271bc2015-11-15 02:50:53 +0100244\fBcurses\fR(3X),
245\fBcurs_kernel\fR(3X),
246\fBcurs_refresh\fR(3X),
247\fBcurs_slk\fR(3X),
248\fBcurs_terminfo\fR(3X),
249\fBcurs_util\fR(3X),
250\fBcurs_variables\fR(3X).