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, may have returned a null pointer
123       from initscr when an error is detected, rather  than  exiting.   It  is
124       safe but redundant to check the return value of initscr in XSI Curses.
125
126   Unset TERM Variable
127       If  the  TERM variable is missing or empty, initscr uses the value “un‐
128       known”, which normally corresponds to a terminal entry with the generic
129       (gn)  capability.   Generic  entries  are  detected  by  setupterm (see
130       curs_terminfo(3X)) and cannot be used for full-screen operation.  Other
131       implementations may handle a missing/empty TERM variable differently.
132
133   Signal Handlers
134       Quoting from X/Open Curses, section 3.1.1:
135
136            Curses  implementations  may  provide  for special handling of the
137            SIGINT, SIGQUIT  and  SIGTSTP  signals  if  their  disposition  is
138            SIG_DFL at the time initscr is called ...
139
140            Any  special  handling  for these signals may remain in effect for
141            the life of the process or until the process changes the  disposi‐
142            tion of the signal.
143
144            None  of the Curses functions are required to be safe with respect
145            to signals ...
146
147       This implementation establishes signal handlers during  initialization,
148       e.g., initscr or newterm.  Applications which must handle these signals
149       should set up the corresponding handlers  after  initializing  the  li‐
150       brary:
151
152       SIGINT
153            The  handler  attempts to cleanup the screen on exit.  Although it
154            usually works as expected, there are limitations:
155
156            •   Walking the SCREEN list is unsafe, since all  list  management
157                is done without any signal blocking.
158
159            •   On systems which have REENTRANT turned on, set_term uses func‐
160                tions which could deadlock or misbehave in other ways.
161
162endwin calls other functions, many of which use stdio or other
163                library functions which are clearly unsafe.
164
165       SIGTERM
166            This  uses  the same handler as SIGINT, with the same limitations.
167            It is not mentioned in X/Open Curses, but  is  more  suitable  for
168            this purpose than SIGQUIT (which is used in debugging).
169
170       SIGTSTP
171            This  handles the stop signal, used in job control.  When resuming
172            the process,  this  implementation  discards  pending  input  with
173            flushinput  (see  curs_util(3X)), and repaints the screen assuming
174            that it has been completely altered.  It also  updates  the  saved
175            terminal modes with def_shell_mode (see curs_kernel(3X)).
176
177       SIGWINCH
178            This  handles  the  window-size  changes which were ignored in the
179            standardization efforts.  The handler sets a  (signal-safe)  vari‐
180            able  which  is  later  tested in wgetch (see curs_getch(3X)).  If
181            keypad has been enabled for the corresponding window,  wgetch  re‐
182            turns  the  key symbol KEY_RESIZE.  At the same time, wgetch calls
183            resizeterm to adjust the standard screen stdscr, and update  other
184            data such as LINES and COLS.
185

SEE ALSO

187       curses(3X),  curs_kernel(3X), curs_refresh(3X), curs_slk(3X), curs_ter‐
188       minfo(3X), curs_util(3X), curs_variables(3X).
189
190
191
192                                                              curs_initscr(3X)
Impressum