Пример #1
0
static void
term_init(int fd, const char *sa[5])
{
	TERMINAL *ti;
	int error;
	const char *bold, *sgr0, *smso, *rmso, *smul, *rmul;

	if (ti_setupterm(&ti, NULL, fd, &error) == -1) {
		bold = sgr0 = NULL;
		smso = rmso = smul = rmul = "";
		ti = NULL;
	} else {
		bold = ti_getstr(ti, "bold");
		sgr0 = ti_getstr(ti, "sgr0");
		if (bold == NULL || sgr0 == NULL) {
			smso = ti_getstr(ti, "smso");

			if (smso == NULL ||
			    (rmso = ti_getstr(ti, "rmso")) == NULL)
				smso = rmso = "";
			bold = sgr0 = NULL;
		} else
			smso = rmso = "";

		smul = ti_getstr(ti, "smul");
		if (smul == NULL || (rmul = ti_getstr(ti, "rmul")) == NULL)
			smul = rmul = "";
	}

	sa[0] = term_fix_seq(ti, bold ? bold : smso);
	sa[1] = term_fix_seq(ti, sgr0 ? sgr0 : rmso);
	sa[2] = estrdup("...");
	sa[3] = term_fix_seq(ti, smul);
	sa[4] = term_fix_seq(ti, rmul);

	if (ti)
		del_curterm(ti);
}
Пример #2
0
int
_cursesi_setterm(char *type, SCREEN *screen)
{
	int unknown, r;
	struct winsize win;
	char *p;

	if (type[0] == '\0')
		type = "xx";
	unknown = 0;
	(void)ti_setupterm(&screen->term, type, fileno(screen->outfd), &r);
	if (screen->term == NULL) {
		unknown++;
		(void)ti_setupterm(&screen->term, "dumb",
		    fileno(screen->outfd), &r);
		/* No dumb term? We can't continue */
		if (screen->term == NULL)
			return ERR;
	}
#ifdef DEBUG
	__CTRACE(__CTRACE_INIT, "setterm: tty = %s\n", type);
#endif

	/* Try TIOCGWINSZ, and, if it fails, the terminfo entry. */
	if (ioctl(fileno(screen->outfd), TIOCGWINSZ, &win) != -1 &&
	    win.ws_row != 0 && win.ws_col != 0) {
		screen->LINES = win.ws_row;
		screen->COLS = win.ws_col;
	}  else {
		if (unknown) {
			screen->LINES = -1;
			screen->COLS = -1;
		} else {
			screen->LINES = t_lines(screen->term);
			screen->COLS = t_columns(screen->term);
		}
		
	}

	/* POSIX 1003.2 requires that the environment override. */
	if ((p = getenv("LINES")) != NULL)
		screen->LINES = (int) strtol(p, NULL, 0);
	if ((p = getenv("COLUMNS")) != NULL)
		screen->COLS = (int) strtol(p, NULL, 0);
	if ((p = getenv("ESCDELAY")) != NULL)
		ESCDELAY = (int) strtol(p, NULL, 0);

	/*
	 * Want cols > 4, otherwise things will fail.
	 */
	if (screen->COLS <= 4)
		return (ERR);

	LINES = screen->LINES;
	COLS = screen->COLS;

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

	/*
	 * set the pad char, only take the first char of the pc capability
	 * as this is all we can use.
	 */
	screen->padchar = t_pad_char(screen->term) ?
	    t_pad_char(screen->term)[0] : 0; 

	/* If no scrolling commands, no quick change. */
	screen->noqch =
  	    (t_change_scroll_region(screen->term) == NULL ||
		t_cursor_home(screen->term) == NULL ||
		(t_parm_index(screen->term) == NULL &&
		    t_scroll_forward(screen->term) == NULL) ||
		(t_parm_rindex(screen->term) == NULL &&
		    t_scroll_reverse(screen->term) == NULL)) &&
	    ((t_parm_insert_line(screen->term) == NULL &&
		t_insert_line(screen->term) == NULL) ||
		(t_parm_delete_line(screen->term) == NULL &&
		    t_delete_line(screen->term) == NULL));

	/*
	 * Precalculate conflict info for color/attribute end commands.
	 */
#ifndef HAVE_WCHAR
	screen->mask_op = __ATTRIBUTES & ~__COLOR;
#else
	screen->mask_op = WA_ATTRIBUTES & ~__COLOR;
#endif /* HAVE_WCHAR */
	if (t_orig_pair(screen->term) != NULL) {
		if (does_esc_m(t_orig_pair(screen->term)))
			screen->mask_op &=
			    ~(__STANDOUT | __UNDERSCORE | __TERMATTR);
		else {
			if (t_exit_standout_mode(screen->term) != NULL &&
			    !strcmp(t_orig_pair(screen->term),
				t_exit_standout_mode(screen->term)))
				screen->mask_op &= ~__STANDOUT;
			if (t_exit_underline_mode(screen->term) != NULL &&
			    !strcmp(t_orig_pair(screen->term),
				t_exit_underline_mode(screen->term)))
				screen->mask_op &= ~__UNDERSCORE;
			if (t_exit_attribute_mode(screen->term) != NULL &&
			    !strcmp(t_orig_pair(screen->term),
				t_exit_attribute_mode(screen->term)))
				screen->mask_op &= ~__TERMATTR;
		}
	}
	/*
	 * Assume that "me" turns off all attributes apart from ACS.
	 * It might turn off ACS, so check for that.
	 */
	if (t_exit_attribute_mode(screen->term) != NULL &&
	    does_ctrl_o(t_exit_attribute_mode(screen->term)))
		screen->mask_me = 0;
	else
		screen->mask_me = __ALTCHARSET;

	/* Check what turning off the attributes also turns off */
#ifndef HAVE_WCHAR
	screen->mask_ue = __ATTRIBUTES & ~__UNDERSCORE;
#else
	screen->mask_ue = WA_ATTRIBUTES & ~__UNDERSCORE;
#endif /* HAVE_WCHAR */
	if (t_exit_underline_mode(screen->term) != NULL) {
		if (does_esc_m(t_exit_underline_mode(screen->term)))
			screen->mask_ue &=
			    ~(__STANDOUT | __TERMATTR | __COLOR);
		else {
			if (t_exit_standout_mode(screen->term) != NULL &&
			    !strcmp(t_exit_underline_mode(screen->term),
				t_exit_standout_mode(screen->term)))
				screen->mask_ue &= ~__STANDOUT;
			if (t_exit_attribute_mode(screen->term) != NULL &&
			    !strcmp(t_exit_underline_mode(screen->term),
				t_exit_attribute_mode(screen->term)))
				screen->mask_ue &= ~__TERMATTR;
			if (t_orig_pair(screen->term) != NULL &&
			    !strcmp(t_exit_underline_mode(screen->term),
				t_orig_pair(screen->term)))
				screen->mask_ue &= ~__COLOR;
		}
	}
#ifndef HAVE_WCHAR
	screen->mask_se = __ATTRIBUTES & ~__STANDOUT;
#else
	screen->mask_se = WA_ATTRIBUTES & ~__STANDOUT;
#endif /* HAVE_WCHAR */
	if (t_exit_standout_mode(screen->term) != NULL) {
		if (does_esc_m(t_exit_standout_mode(screen->term)))
			screen->mask_se &=
			    ~(__UNDERSCORE | __TERMATTR | __COLOR);
		else {
			if (t_exit_underline_mode(screen->term) != NULL &&
			    !strcmp(t_exit_standout_mode(screen->term),
				t_exit_underline_mode(screen->term)))
				screen->mask_se &= ~__UNDERSCORE;
			if (t_exit_attribute_mode(screen->term) != NULL &&
			    !strcmp(t_exit_standout_mode(screen->term),
				t_exit_attribute_mode(screen->term)))
				screen->mask_se &= ~__TERMATTR;
			if (t_orig_pair(screen->term) != NULL &&
			    !strcmp(t_exit_standout_mode(screen->term),
				t_orig_pair(screen->term)))
				screen->mask_se &= ~__COLOR;
		}
	}

	return (unknown ? ERR : OK);
}