Beispiel #1
0
void
tty_check_fg(struct tty *tty, struct grid_cell *gc)
{
	u_int	colours;

	/* Is this a 256-colour colour? */
	if (gc->flags & GRID_FLAG_FG256) {
		/* And not a 256 colour mode? */
		if (!(tty->term->flags & TERM_88COLOURS) &&
		    !(tty->term_flags & TERM_88COLOURS) &&
		    !(tty->term->flags & TERM_256COLOURS) &&
		    !(tty->term_flags & TERM_256COLOURS)) {
			gc->fg = colour_256to16(gc->fg);
			if (gc->fg & 8) {
				gc->fg &= 7;
				gc->attr |= GRID_ATTR_BRIGHT;
			} else
				gc->attr &= ~GRID_ATTR_BRIGHT;
			gc->flags &= ~GRID_FLAG_FG256;
		}
		return;
	}

	/* Is this an aixterm colour? */
	colours = tty_term_number(tty->term, TTYC_COLORS);
	if (gc->fg >= 90 && gc->fg <= 97 && colours < 16) {
		gc->fg -= 90;
		gc->attr |= GRID_ATTR_BRIGHT;
	}
}
Beispiel #2
0
void
tty_check_bg(struct tty *tty, struct grid_cell *gc)
{
	u_int	colours;

	/* Is this a 256-colour colour? */
	if (gc->flags & GRID_FLAG_BG256) {
		/*
		 * And not a 256 colour mode? Translate to 16-colour
		 * palette. Bold background doesn't exist portably, so just
		 * discard the bold bit if set.
		 */
		if (!(tty->term->flags & TERM_88COLOURS) &&
		    !(tty->term_flags & TERM_88COLOURS) &&
		    !(tty->term->flags & TERM_256COLOURS) &&
		    !(tty->term_flags & TERM_256COLOURS)) {
			gc->bg = colour_256to16(gc->bg);
			if (gc->bg & 8)
				gc->bg &= 7;
			gc->attr &= ~GRID_ATTR_BRIGHT;
			gc->flags &= ~GRID_FLAG_BG256;
		}
		return;
	}

	/* Is this an aixterm colour? */
	colours = tty_term_number(tty->term, TTYC_COLORS);
	if (gc->bg >= 100 && gc->bg <= 107 && colours < 16) {
		gc->bg -= 90;
		gc->attr |= GRID_ATTR_BRIGHT;
	}
}
Beispiel #3
0
void
tty_colours_bg(struct tty *tty, const struct grid_cell *gc)
{
	struct grid_cell	*tc = &tty->cell;
	u_char			 bg = gc->bg;
	char			 s[32];

	/* Is this a 256-colour colour? */
	if (gc->flags & GRID_FLAG_BG256) {
		/* Try as 256 colours or translating to 88. */
		if (tty_try_256(tty, bg, "48") == 0)
			goto save_bg;
		if (tty_try_88(tty, bg, "48") == 0)
			goto save_bg;
		/* Else already handled by tty_check_bg. */
		return;
	}

	/* Is this an aixterm bright colour? */
	if (bg >= 100 && bg <= 107) {
		/* 16 colour terminals or above only. */
		if (tty_term_number(tty->term, TTYC_COLORS) >= 16) {
			xsnprintf(s, sizeof s, "\033[%dm", bg);
			tty_puts(tty, s);
			goto save_bg;
		}
		bg -= 100;
		/* no such thing as a bold background */
	}

	/* Otherwise set the background colour. */
	tty_putcode1(tty, TTYC_SETAB, bg);

save_bg:
	/* Save the new values in the terminal current cell. */
	tc->bg = bg;
	tc->flags &= ~GRID_FLAG_BG256;
	tc->flags |= gc->flags & GRID_FLAG_BG256;
}
Beispiel #4
0
/* Should this terminal use ACS instead of UTF-8 line drawing? */
int
tty_acs_needed(struct tty *tty)
{
	if (tty == NULL)
		return (0);

	/*
	 * If the U8 flag is present, it marks whether a terminal supports
	 * UTF-8 and ACS together.
	 *
	 * If it is present and zero, we force ACS - this gives users a way to
	 * turn off UTF-8 line drawing.
	 *
	 * If it is nonzero, we can fall through to the default and use UTF-8
	 * line drawing on UTF-8 terminals.
	 */
	if (tty_term_has(tty->term, TTYC_U8) &&
	    tty_term_number(tty->term, TTYC_U8) == 0)
		return (1);

	if (tty->flags & TTY_UTF8)
		return (0);
	return (1);
}