Пример #1
0
void
tty_attributes_bg(struct tty *tty, const struct grid_cell *gc)
{
	u_char	bg;

	bg = gc->bg;
	if (gc->flags & GRID_FLAG_BG256) {
		if (tty_try_256(tty, bg, "48") == 0)
			return;
		if (tty_try_88(tty, bg, "48") == 0)
			return;
		bg = colour_256to16(bg);
		if (bg & 8)
			bg &= 7;
	}

	if (bg == 8 &&
	    !(tty->term->flags & TERM_HASDEFAULTS) &&
	    !(tty->term_flags & TERM_HASDEFAULTS))
		bg = 0;
	if (bg == 8)
		tty_puts(tty, "\033[49m");
	else
		tty_putcode1(tty, TTYC_SETAB, bg);
}
Пример #2
0
void
tty_colours_fg(struct tty *tty, const struct grid_cell *gc)
{
	struct grid_cell	*tc = &tty->cell;
	u_char			 fg = gc->fg;
	char			 s[32];

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

	/* Is this an aixterm bright colour? */
	if (fg >= 90 && fg <= 97) {
		xsnprintf(s, sizeof s, "\033[%dm", fg);
		tty_puts(tty, s);
		goto save_fg;
	}

	/* Otherwise set the foreground colour. */
	tty_putcode1(tty, TTYC_SETAF, fg);

save_fg:
	/* Save the new values in the terminal current cell. */
	tc->fg = fg;
	tc->flags &= ~GRID_FLAG_FG256;
	tc->flags |= gc->flags & GRID_FLAG_FG256;
}
Пример #3
0
void
tty_attributes_fg(struct tty *tty, const struct grid_cell *gc)
{
	u_char	fg;

	fg = gc->fg;
	if (gc->flags & GRID_FLAG_FG256) {
		if (tty_try_256(tty, fg, "38") == 0)
			return;
		if (tty_try_88(tty, fg, "38") == 0)
			return;
		fg = colour_256to16(fg);
		if (fg & 8) {
			fg &= 7;
			tty_putcode(tty, TTYC_BOLD);
			tty->cell.attr |= GRID_ATTR_BRIGHT;
		} else if (tty->cell.attr & GRID_ATTR_BRIGHT)
			tty_reset(tty);
	}

	if (fg == 8 &&
	    !(tty->term->flags & TERM_HASDEFAULTS) &&
	    !(tty->term_flags & TERM_HASDEFAULTS))
		fg = 7;
	if (fg == 8)
		tty_puts(tty, "\033[39m");
	else
		tty_putcode1(tty, TTYC_SETAF, fg);
}
Пример #4
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;
}