예제 #1
0
/*
 * initscr --
 *	Initialize the current and standard screen.
 */
WINDOW *
initscr()
{
	register char *sp;

#ifdef DEBUG
	__CTRACE("initscr\n");
#endif
	__echoit = 1;
        __pfast = __rawmode = __noqch = 0;

	if (gettmode() == ERR)
		return (NULL);

	/*
	 * If My_term is set, or can't find a terminal in the environment,
	 * use Def_term.
	 */
	if (My_term || (sp = getenv("TERM")) == NULL)
		sp = Def_term;
	if (setterm(sp) == ERR)
		return (NULL);

	/* Need either homing or cursor motion for refreshes */
	if (!HO && !CM) 
		return (NULL);

	if (curscr != NULL)
		delwin(curscr);
	if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
		return (NULL);
	clearok(curscr, 1);

	if (stdscr != NULL)
		delwin(stdscr);
	if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) {
		delwin(curscr);
		return (NULL);
	}

	__set_stophandler();

#ifdef DEBUG
	__CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
#endif
	__startwin();

	return (stdscr);
}
예제 #2
0
void
__restartwin(void)
{
	struct winsize win;
	int nlines, ncols;

#ifdef DEBUG
	__CTRACE(__CTRACE_MISC, "__restartwin\n");
#endif
	if (!_cursesi_screen->endwin)
		return;

	/* Reset the curses SIGTSTP and SIGWINCH signal handlers. */
	__set_stophandler();
	__set_winchhandler();

	/*
	 * Check to see if the window size has changed.
	 * If the application didn't update LINES and COLS,
	 * set the * resized flag to tell getch() to push KEY_RESIZE.
	 * Update curscr (which also updates __virtscr) and stdscr
	 * to match the new size.
	 */
	if (ioctl(fileno(_cursesi_screen->outfd), TIOCGWINSZ, &win) != -1 &&
	    win.ws_row != 0 && win.ws_col != 0) {
		if (win.ws_row != LINES) {
			LINES = win.ws_row;
			_cursesi_screen->resized = 1;
		}
		if (win.ws_col != COLS) {
			COLS = win.ws_col;
			_cursesi_screen->resized = 1;
		}
	}
	/*
	 * We need to make local copies of LINES and COLS, otherwise we
	 * could lose if they are changed between wresize() calls.
	 */
	nlines = LINES;
	ncols = COLS;
	if (curscr->maxy != nlines || curscr->maxx != ncols)
		wresize(curscr, nlines, ncols);
	if (stdscr->maxy != nlines || stdscr->maxx != ncols)
		wresize(stdscr, nlines, ncols);

	/* save the new "default" terminal state */
	(void) tcgetattr(fileno(_cursesi_screen->infd),
			 &_cursesi_screen->orig_termios);

	/* Reset the terminal state to the mode just before we stopped. */
	(void) tcsetattr(fileno(_cursesi_screen->infd), TCSASOFT | TCSADRAIN,
	    &_cursesi_screen->save_termios);

	/* Restore colours */
	__restore_colors();

	/* Reset meta */
	__restore_meta_state();

	/* Restart the screen. */
	__startwin(_cursesi_screen);

	/* Reset cursor visibility */
	__restore_cursor_vis();

	/* Repaint the screen. */
	wrefresh(curscr);
}