1 /* $NetBSD: screen.c,v 1.23 2010/06/10 05:24:55 dholland Exp $ */
4 * Copyright (c) 1981, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)screen.c 8.2 (blymn) 11/27/2001";
37 __RCSID("$NetBSD: screen.c,v 1.23 2010/06/10 05:24:55 dholland Exp $");
44 #include "curses_private.h"
48 * Change the term to the given screen.
54 SCREEN
*old_screen
= _cursesi_screen
;
56 if (_cursesi_screen
!= NULL
) {
57 /* save changes made to the current screen... */
58 old_screen
->echoit
= __echoit
;
59 old_screen
->pfast
= __pfast
;
60 old_screen
->rawmode
= __rawmode
;
61 old_screen
->noqch
= __noqch
;
62 old_screen
->COLS
= COLS
;
63 old_screen
->LINES
= LINES
;
64 old_screen
->COLORS
= COLORS
;
65 old_screen
->COLOR_PAIRS
= COLOR_PAIRS
;
66 old_screen
->GT
= __GT
;
67 old_screen
->NONL
= __NONL
;
68 old_screen
->UPPERCASE
= __UPPERCASE
;
71 _cursesi_screen
= new;
73 __echoit
= new->echoit
;
75 __rawmode
= new->rawmode
;
80 COLOR_PAIRS
= new->COLOR_PAIRS
;
83 __UPPERCASE
= new->UPPERCASE
;
85 _cursesi_resetterm(new);
88 clearok(curscr
, new->clearok
);
90 __virtscr
= new->__virtscr
;
92 _cursesi_reset_acs(new);
94 _cursesi_reset_wacs(new);
95 #endif /* HAVE_WCHAR */
98 __CTRACE(__CTRACE_SCREEN
, "set_term: LINES = %d, COLS = %d\n",
107 * Set up a new screen.
111 newterm(char *type
, FILE *outfd
, FILE *infd
)
117 if ((type
== NULL
) && (sp
= getenv("TERM")) == NULL
)
120 if ((new_screen
= calloc(1, sizeof(SCREEN
))) == NULL
)
124 __CTRACE(__CTRACE_INIT
, "newterm\n");
127 new_screen
->infd
= infd
;
128 new_screen
->outfd
= outfd
;
129 new_screen
->echoit
= new_screen
->nl
= 1;
130 new_screen
->pfast
= new_screen
->rawmode
= new_screen
->noqch
= 0;
131 new_screen
->nca
= A_NORMAL
;
132 new_screen
->color_type
= COLOR_NONE
;
133 new_screen
->COLOR_PAIRS
= 0;
134 new_screen
->old_mode
= 2;
135 new_screen
->stdbuf
= NULL
;
136 new_screen
->stdscr
= NULL
;
137 new_screen
->curscr
= NULL
;
138 new_screen
->__virtscr
= NULL
;
139 new_screen
->curwin
= 0;
140 new_screen
->notty
= FALSE
;
141 new_screen
->half_delay
= FALSE
;
142 new_screen
->resized
= 0;
143 new_screen
->unget_len
= 32;
145 if ((new_screen
->unget_list
=
146 malloc(sizeof(wchar_t) * new_screen
->unget_len
)) == NULL
) {
149 new_screen
->unget_pos
= 0;
151 if (_cursesi_gettmode(new_screen
) == ERR
)
154 if (_cursesi_setterm((char *)sp
, new_screen
) == ERR
)
157 /* Need either homing or cursor motion for refreshes */
158 if (!t_cursor_home(new_screen
->term
) &&
159 !t_cursor_address(new_screen
->term
))
162 new_screen
->winlistp
= NULL
;
164 if ((new_screen
->curscr
= __newwin(new_screen
, 0,
165 0, 0, 0, FALSE
)) == NULL
)
168 if ((new_screen
->stdscr
= __newwin(new_screen
, 0,
169 0, 0, 0, FALSE
)) == NULL
) {
170 delwin(new_screen
->curscr
);
174 clearok(new_screen
->stdscr
, 1);
176 if ((new_screen
->__virtscr
= __newwin(new_screen
, 0,
177 0, 0, 0, FALSE
)) == NULL
) {
178 delwin(new_screen
->curscr
);
179 delwin(new_screen
->stdscr
);
183 __init_getch(new_screen
);
184 __init_acs(new_screen
);
186 __init_get_wch( new_screen
);
187 __init_wacs(new_screen
);
188 #endif /* HAVE_WCHAR */
191 __set_winchhandler();
194 * bleh - it seems that apps expect the first newterm to set
195 * up the curses screen.... emulate this.
197 if (_cursesi_screen
== NULL
|| _cursesi_screen
->endwin
) {
198 set_term(new_screen
);
202 __CTRACE(__CTRACE_SCREEN
, "newterm: LINES = %d, COLS = %d\n",
205 __startwin(new_screen
);
216 * Free resources used by the given screen and destroy it.
220 delscreen(SCREEN
*screen
)
222 struct __winlist
*list
;
225 __CTRACE(__CTRACE_SCREEN
, "delscreen(%p)\n", screen
);
227 /* free up the terminfo stuff */
228 del_curterm(screen
->term
);
230 /* walk the window list and kill all the parent windows */
231 while ((list
= screen
->winlistp
) != NULL
) {
233 if (list
== screen
->winlistp
)
234 /* sanity - abort if window didn't remove itself */
238 /* free the storage of the keymaps */
239 _cursesi_free_keymap(screen
->base_keymap
);
241 free(screen
->stdbuf
);
242 screen
->stdbuf
= NULL
;
243 if (_cursesi_screen
== screen
)
244 _cursesi_screen
= NULL
;