1 /****************************************************************************
2 * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
37 ** The routine set_term().
41 #include <curses.priv.h>
43 #include <term.h> /* cur_term */
46 MODULE_ID("$Id: lib_set_term.c,v 1.58 2000/10/04 22:05:48 tom Exp $")
49 set_term(SCREEN * screenp)
53 T((T_CALLED("set_term(%p)"), screenp));
56 _nc_set_screen(screenp);
58 set_curterm(SP->_term);
62 COLORS = SP->_color_count;
63 COLOR_PAIRS = SP->_pair_count;
64 memcpy(acs_map, SP->_acs_map, sizeof(chtype) * ACS_LEN);
66 T((T_RETURN("%p"), oldSP));
71 _nc_free_keytry(struct tries *kt)
74 _nc_free_keytry(kt->child);
75 _nc_free_keytry(kt->sibling);
81 * Free the storage associated with the given SCREEN sp.
84 delscreen(SCREEN * sp)
86 SCREEN **scan = &_nc_screen_chain;
88 T((T_CALLED("delscreen(%p)"), sp));
92 *scan = sp->_next_screen;
95 scan = &(*scan)->_next_screen;
98 _nc_freewin(sp->_curscr);
99 _nc_freewin(sp->_newscr);
100 _nc_freewin(sp->_stdscr);
101 _nc_free_keytry(sp->_keytry);
102 _nc_free_keytry(sp->_key_ok);
104 FreeIfNeeded(sp->_color_table);
105 FreeIfNeeded(sp->_color_pairs);
107 FreeIfNeeded(sp->oldhash);
108 FreeIfNeeded(sp->newhash);
110 del_curterm(sp->_term);
113 * If the associated output stream has been closed, we can discard the
114 * set-buffer. Limit the error check to EBADF, since fflush may fail
115 * for other reasons than trying to operate upon a closed stream.
119 && fflush(sp->_ofp) != 0
127 * If this was the current screen, reset everything that the
128 * application might try to use (except cur_term, which may have
129 * multiple references in different screens).
142 static ripoff_t rippedoff[5];
143 static ripoff_t *rsp = rippedoff;
144 #define N_RIPS SIZEOF(rippedoff)
147 no_mouse_event(SCREEN * sp GCC_UNUSED)
153 no_mouse_inline(SCREEN * sp GCC_UNUSED)
159 no_mouse_parse(int code GCC_UNUSED)
165 no_mouse_resume(SCREEN * sp GCC_UNUSED)
170 no_mouse_wrap(SCREEN * sp GCC_UNUSED)
174 #if NCURSES_EXT_FUNCS && USE_COLORFGBG
176 extract_fgbg(char *src, int *result)
179 long value = strtol(src, &dst, 0);
183 } else if (value >= 0) {
184 *result = value % max_colors;
186 while (*dst != 0 && *dst != ';')
195 _nc_setupscreen(short slines, short const scolumns, FILE * output)
196 /* OS-independent screen initializations */
198 int bottom_stolen = 0;
201 assert(SP == 0); /* has been reset in newterm() ! */
202 if (!_nc_alloc_screen())
205 SP->_next_screen = _nc_screen_chain;
206 _nc_screen_chain = SP;
208 _nc_set_buffer(output, TRUE);
209 SP->_term = cur_term;
211 SP->_lines_avail = slines;
212 SP->_columns = scolumns;
222 SP->_cursor = -1; /* cannot know real cursor shape */
224 #if NCURSES_NO_PADDING
225 SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0;
226 TR(TRACE_CHARPUT | TRACE_MOVE, ("padding will%s be used",
227 SP->_no_padding ? " not" : ""));
230 #if NCURSES_EXT_FUNCS
231 SP->_default_color = FALSE;
232 SP->_has_sgr_39_49 = FALSE;
235 * Set our assumption of the terminal's default foreground and background
236 * colors. The curs_color man-page states that we can assume that the
237 * background is black. The origin of this assumption appears to be
238 * terminals that displayed colored text, but no colored backgrounds, e.g.,
239 * the first colored terminals around 1980. More recent ones with better
240 * technology can display not only colored backgrounds, but all
241 * combinations. So a terminal might be something other than "white" on
242 * black (green/black looks monochrome too), but black on white or even
245 * White-on-black is the simplest thing to use for monochrome. Almost
246 * all applications that use color paint both text and background, so
247 * the distinction is moot. But a few do not - which is why we leave this
248 * configurable (a better solution is to use assume_default_colors() for
249 * the rare applications that do require that sort of appearance, since
250 * is appears that more users expect to be able to make a white-on-black
251 * or black-on-white display under control of the application than not).
253 #ifdef USE_ASSUMED_COLOR
254 SP->_default_fg = COLOR_WHITE;
255 SP->_default_bg = COLOR_BLACK;
257 SP->_default_fg = C_MASK;
258 SP->_default_bg = C_MASK;
263 * If rxvt's $COLORFGBG variable is set, use it to specify the assumed
264 * default colors. Note that rxvt (mis)uses bold colors, equating a bold
265 * color to that value plus 8. We'll only use the non-bold color for now -
266 * decide later if it is worth having default attributes as well.
268 if (getenv("COLORFGBG") != 0) {
269 char *p = getenv("COLORFGBG");
270 p = extract_fgbg(p, &(SP->_default_fg));
271 p = extract_fgbg(p, &(SP->_default_bg));
274 #endif /* NCURSES_EXT_FUNCS */
276 SP->_maxclick = DEFAULT_MAXCLICK;
277 SP->_mouse_event = no_mouse_event;
278 SP->_mouse_inline = no_mouse_inline;
279 SP->_mouse_parse = no_mouse_parse;
280 SP->_mouse_resume = no_mouse_resume;
281 SP->_mouse_wrap = no_mouse_wrap;
284 /* initialize the panel hooks */
285 SP->_panelHook.top_panel = (struct panel *) 0;
286 SP->_panelHook.bottom_panel = (struct panel *) 0;
287 SP->_panelHook.stdscr_pseudo_panel = (struct panel *) 0;
290 * If we've no magic cookie support, we suppress attributes that xmc
291 * would affect, i.e., the attributes that affect the rendition of a
292 * space. Note that this impacts the alternate character set mapping
295 if (magic_cookie_glitch > 0) {
297 SP->_xmc_triggers = termattrs() & (
305 SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~ (A_BOLD);
307 T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
310 * To keep this simple, suppress all of the optimization hooks
311 * except for clear_screen and the cursor addressing.
317 magic_cookie_glitch = ABSENT_NUMERIC;
322 memcpy(SP->_acs_map, acs_map, sizeof(chtype) * ACS_LEN);
327 _nc_windows = 0; /* no windows yet */
332 T(("creating newscr"));
333 if ((newscr = newwin(slines, scolumns, 0, 0)) == 0)
336 T(("creating curscr"));
337 if ((curscr = newwin(slines, scolumns, 0, 0)) == 0)
340 SP->_newscr = newscr;
341 SP->_curscr = curscr;
343 SP->_resize = resizeterm;
346 newscr->_clear = TRUE;
347 curscr->_clear = FALSE;
349 for (i = 0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, i++) {
352 int count = (rsp->line < 0) ? -rsp->line : rsp->line;
355 w = newwin(count, scolumns, SP->_lines_avail - count, 0);
358 rsp->hook(w, scolumns);
359 bottom_stolen += count;
363 w = newwin(count, scolumns, 0, 0);
366 rsp->hook(w, scolumns);
367 SP->_topstolen += count;
371 SP->_lines_avail -= count;
375 /* reset the stack */
378 T(("creating stdscr"));
379 assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines);
380 if ((stdscr = newwin(LINES = SP->_lines_avail, scolumns, 0, 0)) == 0)
382 SP->_stdscr = stdscr;
390 /* The internal implementation interprets line as the number of
391 lines to rip off from the top or bottom.
394 _nc_ripoffline(int line, int (*init) (WINDOW *, int))
399 if (rsp >= rippedoff + N_RIPS)
411 ripoffline(int line, int (*init) (WINDOW *, int))
413 T((T_CALLED("ripoffline(%d,%p)"), line, init));
418 returnCode(_nc_ripoffline((line < 0) ? -1 : 1, init));