Exemplo n.º 1
0
// Handle any terminal resize that has happened since the last
// `term_init' or `term_check_resize'.  Return true if there was a
// resize.
bool
term_check_resize(void)
{
        if (!term_need_resize)
                return false;

        term_need_resize = 0;
        // restartterm is overkill, but appears to be the only way to
        // get ncurses to update the terminal size when using the
        // low-level routines.
        restartterm(NULL, 1, NULL);
        return true;
}
Exemplo n.º 2
0
static void
test_setupterm(NCURSES_CONST char *name)
{
    int rc;
    int err = -99;

    if (r_opt) {
	rc = restartterm(name, 0, f_opt ? NULL : &err);
    } else {
	rc = setupterm(name, 0, f_opt ? NULL : &err);
    }
    test_rc(name, rc, err);
}
Exemplo n.º 3
0
/*
 * Set up terminal.
 *
 * Reads in the terminfo database pointed to by $TERMINFO env. var.
 * for the given terminal, but does not set up the output virtualization
 * structues used by CURSES.  If the terminal name pointer is NULL,
 * the $TERM env. var. is used for the terminal.  All output is to
 * the given file descriptor which is initialized for output.
 *
 * On error, if errret != NULL then setupterm() returns OK
 * or ERR and stores a status value in the integer pointed to by
 * errret.  A status of 1 is normal, 0 means the terminal could
 * not be found, and -1 means the terminfo database could not be
 * found.  If errret == NULL then setupterm() prints an error
 * message upon and exit().
 *
 * On success, cur_term set to a terminfo structure and OK returned.
 */
int
__m_setupterm(char *termname, int ifd, int ofd, int *err_return)
{
	int	err_code = 1;
	TERMINAL	*old_term;
	const char 	*err_msg;

	/*
	 * It is possible to call setupterm() for multiple terminals,
	 * in which case we have to be able to restore cur_term in
	 * case of error.
	 */
	old_term = cur_term;

	cur_term = (TERMINAL *) calloc(1, sizeof (*cur_term));
	if (cur_term == NULL) {
		err_code = -1;
		goto error;
	}

	if (isatty(cur_term->_ifd = ifd))
		cur_term->_flags |= __TERM_ISATTY_IN;
	if (isatty(cur_term->_ofd = ofd))
		cur_term->_flags |= __TERM_ISATTY_OUT;

	cur_term->_shell	= (void *) calloc(1, sizeof (struct termios));
	cur_term->_prog		= (void *) calloc(1, sizeof (struct termios));
	cur_term->_save		= (void *) calloc(1, sizeof (struct termios));
	cur_term->_actual	= (void *) calloc(1, sizeof (struct termios));
	cur_term->_term		= NULL;
	cur_term->_names	= NULL;
	cur_term->_str_table	= NULL;
	(void) def_shell_mode();
	(void) def_prog_mode();
	(void) __m_tty_get(PTERMIOS(_actual));	/* Synch cached value */

#ifdef ONLCR
	if ((PTERMIOS(_prog)->c_oflag & (OPOST | ONLCR)) == (OPOST | ONLCR))
#else
	if (PTERMIOS(_prog)->c_oflag & OPOST)
#endif
		cur_term->_flags |= __TERM_NL_IS_CRLF;

	(void) restartterm(termname, ofd, &err_code);
error:
	switch (err_code) {
	case -1:
		err_msg = e_terminal;
		break;
	case 0:
		err_msg = e_unknown;
		break;
	case 1:
		break;
	case 2:
		err_msg = e_pathmax;
		err_code = -1;
		break;
	}

	if (err_return != NULL) {
		*err_return = err_code;

		if (err_code == 1) {
			err_code = OK;
		} else {
			err_code = ERR;
			free(cur_term);
			cur_term = old_term;
		}
	} else if (err_code != 1) {
		(void) fprintf(stderr, err_msg, termname);
		exit(1);
	}

	return (err_code);
}