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; } }
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); }
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; } }
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); }