Esempio n. 1
0
/* ASCLRL() -- Clear to end of line from current position */
static void asclrl(int pos, int width)
{
   int i;

   if (t_cl) {
       t_send(t_cl);                 /* use clear to eol function */
       return;
   }
   if (pos==1 && linsdel_ok) {
       t_delete_line();              /* delete line */
       t_insert_line();              /* reinsert it */
       return;
   }
   for (i=1; i<=width-pos+1; i++)
       t_char(' ');                  /* last resort, blank it out */
   for (i=1; i<=width-pos+1; i++)    /* backspace to original position */
       t_char(0x8);
   return;

}
Esempio n. 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);
}