1curs_initscr(3X) curs_initscr(3X)
2
3
4
6 initscr, newterm, endwin, isendwin, set_term, delscreen - curses screen
7 initialization and manipulation routines
8
10 #include <curses.h>
11
12 WINDOW *initscr(void);
13 int endwin(void);
14 bool isendwin(void);
15 SCREEN *newterm(char *type, FILE *outfd, FILE *infd);
16 SCREEN *set_term(SCREEN *new);
17 void delscreen(SCREEN* sp);
18
20 initscr
21 initscr is normally the first curses routine to call when initializing
22 a program. A few special routines sometimes need to be called before
23 it; these are slk_init(3X), filter, ripoffline, use_env. For multiple-
24 terminal applications, newterm may be called before initscr.
25
26 The initscr code determines the terminal type and initializes all curs‐
27 es data structures. initscr also causes the first call to refresh(3X)
28 to clear the screen. If errors occur, initscr writes an appropriate
29 error message to standard error and exits; otherwise, a pointer is re‐
30 turned to stdscr.
31
32 newterm
33 A program that outputs to more than one terminal should use the newterm
34 routine for each terminal instead of initscr. A program that needs to
35 inspect capabilities, so it can continue to run in a line-oriented mode
36 if the terminal cannot support a screen-oriented program, would also
37 use newterm. The routine newterm should be called once for each termi‐
38 nal. It returns a variable of type SCREEN * which should be saved as a
39 reference to that terminal. newterm's arguments are
40
41 · the type of the terminal to be used in place of $TERM,
42
43 · a file pointer for output to the terminal, and
44
45 · another file pointer for input from the terminal
46
47 If the type parameter is NULL, $TERM will be used.
48
49 endwin
50 The program must also call endwin for each terminal being used before
51 exiting from curses. If newterm is called more than once for the same
52 terminal, the first terminal referred to must be the last one for which
53 endwin is called.
54
55 A program should always call endwin before exiting or escaping from
56 curses mode temporarily. This routine
57
58 · resets colors to correspond with the default color pair 0,
59
60 · moves the cursor to the lower left-hand corner of the screen,
61
62 · clears the remainder of the line so that it uses the default col‐
63 ors,
64
65 · sets the cursor to normal visibility (see curs_set(3X)),
66
67 · stops cursor-addressing mode using the exit_ca_mode terminal capa‐
68 bility,
69
70 · restores tty modes (see reset_shell_mode(3X)).
71
72 Calling refresh(3X) or doupdate(3X) after a temporary escape causes the
73 program to resume visual mode.
74
75 isendwin
76 The isendwin routine returns TRUE if endwin has been called without any
77 subsequent calls to wrefresh, and FALSE otherwise.
78
79 set_term
80 The set_term routine is used to switch between different terminals.
81 The screen reference new becomes the new current terminal. The previ‐
82 ous terminal is returned by the routine. This is the only routine
83 which manipulates SCREEN pointers; all other routines affect only the
84 current terminal.
85
86 delscreen
87 The delscreen routine frees storage associated with the SCREEN data
88 structure. The endwin routine does not do this, so delscreen should be
89 called after endwin if a particular SCREEN is no longer needed.
90
92 endwin returns the integer ERR upon failure and OK upon successful com‐
93 pletion.
94
95 Routines that return pointers always return NULL on error.
96
97 X/Open defines no error conditions. In this implementation
98
99 · endwin returns an error if the terminal was not initialized.
100
101 · newterm returns an error if it cannot allocate the data structures
102 for the screen, or for the top-level windows within the screen,
103 i.e., curscr, newscr, or stdscr.
104
105 · set_term returns no error.
106
108 These functions were described in the XSI Curses standard, Issue 4. As
109 of 2015, the current document is X/Open Curses, Issue 7.
110
111 Differences
112 X/Open specifies that portable applications must not call initscr more
113 than once:
114
115 · The portable way to use initscr is once only, using refresh (see
116 curs_refresh(3X)) to restore the screen after endwin.
117
118 · This implementation allows using initscr after endwin.
119
120 Old versions of curses, e.g., BSD 4.4, may have returned a null pointer
121 from initscr when an error is detected, rather than exiting. It is
122 safe but redundant to check the return value of initscr in XSI Curses.
123
124 Unset TERM Variable
125 If the TERM variable is missing or empty, initscr uses the value “un‐
126 known”, which normally corresponds to a terminal entry with the generic
127 (gn) capability. Generic entries are detected by setupterm (see
128 curs_terminfo(3X)) and cannot be used for full-screen operation. Other
129 implementations may handle a missing/empty TERM variable differently.
130
131 Signal Handlers
132 Quoting from X/Open Curses, section 3.1.1:
133
134 Curses implementations may provide for special handling of the
135 SIGINT, SIGQUIT and SIGTSTP signals if their disposition is
136 SIG_DFL at the time initscr is called ...
137
138 Any special handling for these signals may remain in effect for
139 the life of the process or until the process changes the disposi‐
140 tion of the signal.
141
142 None of the Curses functions are required to be safe with respect
143 to signals ...
144
145 This implementation establishes signal handlers during initialization,
146 e.g., initscr or newterm. Applications which must handle these signals
147 should set up the corresponding handlers after initializing the li‐
148 brary:
149
150 SIGINT
151 The handler attempts to cleanup the screen on exit. Although it
152 usually works as expected, there are limitations:
153
154 · Walking the SCREEN list is unsafe, since all list management
155 is done without any signal blocking.
156
157 · On systems which have REENTRANT turned on, set_term uses func‐
158 tions which could deadlock or misbehave in other ways.
159
160 · endwin calls other functions, many of which use stdio or other
161 library functions which are clearly unsafe.
162
163 SIGTERM
164 This uses the same handler as SIGINT, with the same limitations.
165 It is not mentioned in X/Open Curses, but is more suitable for
166 this purpose than SIGQUIT (which is used in debugging).
167
168 SIGTSTP
169 This handles the stop signal, used in job control. When resuming
170 the process, this implementation discards pending input with
171 flushinput (see curs_util(3X)), and repaints the screen assuming
172 that it has been completely altered. It also updates the saved
173 terminal modes with def_shell_mode (see curs_kernel(3X)).
174
175 SIGWINCH
176 This handles the window-size changes which were ignored in the
177 standardization efforts. The handler sets a (signal-safe) vari‐
178 able which is later tested in wgetch (see curs_getch(3X)). If
179 keypad has been enabled for the corresponding window, wgetch re‐
180 turns the key symbol KEY_RESIZE. At the same time, wgetch calls
181 resizeterm to adjust the standard screen stdscr, and update other
182 data such as LINES and COLS.
183
185 curses(3X), curs_kernel(3X), curs_refresh(3X), curs_slk(3X), curs_ter‐
186 minfo(3X), curs_util(3X), curs_variables(3X).
187
188
189
190 curs_initscr(3X)