1curs_initscr(3X)                                              curs_initscr(3X)
2
3
4

NAME

6       initscr, newterm, endwin, isendwin, set_term, delscreen - curses screen
7       initialization and manipulation routines
8

SYNOPSIS

10       #include <curses.h>
11
12       WINDOW *initscr(void);
13       int endwin(void);
14
15       bool isendwin(void);
16
17       SCREEN *newterm(const char *type, FILE *outfd, FILE *infd);
18       SCREEN *set_term(SCREEN *new);
19       void delscreen(SCREEN* sp);
20

DESCRIPTION

22   initscr
23       initscr is normally the first curses routine to call when  initializing
24       a  program.   A few special routines sometimes need to be called before
25       it; these are slk_init(3X), filter, ripoffline, use_env.  For multiple-
26       terminal applications, newterm may be called before initscr.
27
28       The initscr code determines the terminal type and initializes all curs‐
29       es data structures.  initscr also causes the first call to  refresh(3X)
30       to  clear  the  screen.  If errors occur, initscr writes an appropriate
31       error message to standard error and exits; otherwise, a pointer is  re‐
32       turned to stdscr.
33
34   newterm
35       A program that outputs to more than one terminal should use the newterm
36       routine for each terminal instead of initscr.  A program that needs  to
37       inspect capabilities, so it can continue to run in a line-oriented mode
38       if the terminal cannot support a screen-oriented  program,  would  also
39       use newterm.  The routine newterm should be called once for each termi‐
40       nal.  It returns a variable of type SCREEN * which should be saved as a
41       reference to that terminal.  newterm's arguments are
42
43       •   the type of the terminal to be used in place of $TERM,
44
45       •   a file pointer for output to the terminal, and
46
47       •   another file pointer for input from the terminal
48
49       If the type parameter is NULL, $TERM will be used.
50
51   endwin
52       The  program  must also call endwin for each terminal being used before
53       exiting from curses.  If newterm is called more than once for the  same
54       terminal, the first terminal referred to must be the last one for which
55       endwin is called.
56
57       A program should always call endwin before  exiting  or  escaping  from
58       curses mode temporarily.  This routine
59
60       •   resets colors to correspond with the default color pair 0,
61
62       •   moves the cursor to the lower left-hand corner of the screen,
63
64       •   clears  the  remainder of the line so that it uses the default col‐
65           ors,
66
67       •   sets the cursor to normal visibility (see curs_set(3X)),
68
69       •   stops cursor-addressing mode using the exit_ca_mode terminal  capa‐
70           bility,
71
72       •   restores tty modes (see reset_shell_mode(3X)).
73
74       Calling refresh(3X) or doupdate(3X) after a temporary escape causes the
75       program to resume visual mode.
76
77   isendwin
78       The isendwin routine returns TRUE if endwin has been called without any
79       subsequent calls to wrefresh, and FALSE otherwise.
80
81   set_term
82       The  set_term  routine  is  used to switch between different terminals.
83       The screen reference new becomes the new current terminal.  The  previ‐
84       ous  terminal  is  returned  by  the routine.  This is the only routine
85       which manipulates SCREEN pointers; all other routines affect  only  the
86       current terminal.
87
88   delscreen
89       The  delscreen  routine  frees  storage associated with the SCREEN data
90       structure.  The endwin routine does not do this, so delscreen should be
91       called after endwin if a particular SCREEN is no longer needed.
92

RETURN VALUE

94       endwin returns the integer ERR upon failure and OK upon successful com‐
95       pletion.
96
97       Routines that return pointers always return NULL on error.
98
99       X/Open defines no error conditions.  In this implementation
100
101endwin returns an error if the terminal was not initialized.
102
103newterm returns an error if it cannot allocate the data  structures
104           for  the  screen,  or  for the top-level windows within the screen,
105           i.e., curscr, newscr, or stdscr.
106
107set_term returns no error.
108

PORTABILITY

110       These functions were described in the XSI Curses standard, Issue 4.  As
111       of 2015, the current document is X/Open Curses, Issue 7.
112
113   Differences
114       X/Open  specifies that portable applications must not call initscr more
115       than once:
116
117       •   The portable way to use initscr is once only,  using  refresh  (see
118           curs_refresh(3X)) to restore the screen after endwin.
119
120       •   This implementation allows using initscr after endwin.
121
122       Old versions of curses, e.g., BSD 4.4, would return a null pointer from
123       initscr when an error is detected, rather than exiting.  It is safe but
124       redundant to check the return value of initscr in XSI Curses.
125
126       Calling  endwin  does not dispose of the memory allocated in initscr or
127       newterm.  Deleting a SCREEN provides a way to do this:
128
129       •   X/Open Curses does not say what happens to WINDOWs  when  delscreen
130           “frees  storage associated with the SCREEN” nor does the SVr4 docu‐
131           mentation help, adding that it should be called after endwin  if  a
132           SCREEN is no longer needed.
133
134       •   However,  WINDOWs are implicitly associated with a SCREEN.  so that
135           it is reasonable to expect delscreen to deal with these.
136
137       •   SVr4 curses deletes  the  standard  WINDOW  structures  stdscr  and
138           curscr  as  well  as a work area newscr.  SVr4 curses ignores other
139           windows.
140
141       •   Since version 4.0 (1996), ncurses has maintained a list of all win‐
142           dows  for  each screen, using that information to delete those win‐
143           dows when delscreen is called.
144
145       •   NetBSD copied this feature of ncurses in  2001.   PDCurses  follows
146           the SVr4 model, deleting only the standard WINDOW structures.
147
148   Unset TERM Variable
149       If  the  TERM variable is missing or empty, initscr uses the value “un‐
150       known”, which normally corresponds to a terminal entry with the generic
151       (gn)  capability.   Generic  entries  are  detected  by  setupterm (see
152       curs_terminfo(3X)) and cannot be used for full-screen operation.  Other
153       implementations may handle a missing/empty TERM variable differently.
154
155   Signal Handlers
156       Quoting from X/Open Curses, section 3.1.1:
157
158            Curses  implementations  may  provide  for special handling of the
159            SIGINT, SIGQUIT  and  SIGTSTP  signals  if  their  disposition  is
160            SIG_DFL at the time initscr is called ...
161
162            Any  special  handling  for these signals may remain in effect for
163            the  life  of  the  process  or  until  the  process  changes  the
164            disposition of the signal.
165
166            None  of the Curses functions are required to be safe with respect
167            to signals ...
168
169       This implementation establishes signal handlers during  initialization,
170       e.g., initscr or newterm.  Applications which must handle these signals
171       should set up the corresponding handlers  after  initializing  the  li‐
172       brary:
173
174       SIGINT
175            The  handler  attempts to cleanup the screen on exit.  Although it
176            usually works as expected, there are limitations:
177
178            •   Walking the SCREEN list is unsafe, since all  list  management
179                is done without any signal blocking.
180
181            •   On systems which have REENTRANT turned on, set_term uses func‐
182                tions which could deadlock or misbehave in other ways.
183
184endwin calls other functions, many of which use stdio or other
185                library functions which are clearly unsafe.
186
187       SIGTERM
188            This  uses  the same handler as SIGINT, with the same limitations.
189            It is not mentioned in X/Open Curses, but  is  more  suitable  for
190            this purpose than SIGQUIT (which is used in debugging).
191
192       SIGTSTP
193            This  handles the stop signal, used in job control.  When resuming
194            the process,  this  implementation  discards  pending  input  with
195            flushinput  (see  curs_util(3X)), and repaints the screen assuming
196            that it has been completely altered.  It also  updates  the  saved
197            terminal modes with def_shell_mode (see curs_kernel(3X)).
198
199       SIGWINCH
200            This  handles  the  window-size  changes which were ignored in the
201            standardization efforts.  The handler sets a  (signal-safe)  vari‐
202            able  which  is  later  tested in wgetch (see curs_getch(3X)).  If
203            keypad has been enabled for the corresponding window,  wgetch  re‐
204            turns  the  key symbol KEY_RESIZE.  At the same time, wgetch calls
205            resizeterm to adjust the standard screen stdscr, and update  other
206            data such as LINES and COLS.
207

SEE ALSO

209       curses(3X),  curs_kernel(3X), curs_refresh(3X), curs_slk(3X), curs_ter‐
210       minfo(3X), curs_util(3X), curs_variables(3X).
211
212
213
214                                                              curs_initscr(3X)
Impressum