version 1.84, 2010/02/24 19:08:39 |
version 1.85, 2010/03/01 22:44:31 |
|
|
int tty_try_256(struct tty *, u_char, const char *); |
int tty_try_256(struct tty *, u_char, const char *); |
int tty_try_88(struct tty *, u_char, const char *); |
int tty_try_88(struct tty *, u_char, const char *); |
|
|
void tty_colours(struct tty *, const struct grid_cell *, u_char *); |
void tty_colours(struct tty *, const struct grid_cell *); |
void tty_colours_fg(struct tty *, const struct grid_cell *, u_char *); |
void tty_check_fg(struct tty *, struct grid_cell *); |
|
void tty_check_bg(struct tty *, struct grid_cell *); |
|
void tty_colours_fg(struct tty *, const struct grid_cell *); |
void tty_colours_bg(struct tty *, const struct grid_cell *); |
void tty_colours_bg(struct tty *, const struct grid_cell *); |
|
|
void tty_redraw_region(struct tty *, const struct tty_ctx *); |
void tty_redraw_region(struct tty *, const struct tty_ctx *); |
|
|
tty_attributes(struct tty *tty, const struct grid_cell *gc) |
tty_attributes(struct tty *tty, const struct grid_cell *gc) |
{ |
{ |
struct grid_cell *tc = &tty->cell, gc2; |
struct grid_cell *tc = &tty->cell, gc2; |
u_char changed, new_attr; |
u_char changed; |
|
|
/* If the character is space, don't care about foreground. */ |
memcpy(&gc2, gc, sizeof gc2); |
if (gc->data == ' ' && !(gc->flags & GRID_FLAG_UTF8)) { |
|
memcpy(&gc2, gc, sizeof gc2); |
|
if (gc->attr & GRID_ATTR_REVERSE) |
|
gc2.bg = tc->bg; |
|
else |
|
gc2.fg = tc->fg; |
|
gc = &gc2; |
|
} |
|
|
|
/* |
/* |
* If no setab, try to use the reverse attribute as a best-effort for a |
* If no setab, try to use the reverse attribute as a best-effort for a |
|
|
* any serious harm and makes a couple of applications happier. |
* any serious harm and makes a couple of applications happier. |
*/ |
*/ |
if (!tty_term_has(tty->term, TTYC_SETAB)) { |
if (!tty_term_has(tty->term, TTYC_SETAB)) { |
if (gc != &gc2) { |
if (gc2.attr & GRID_ATTR_REVERSE) { |
memcpy(&gc2, gc, sizeof gc2); |
if (gc2.fg != 7 && gc2.fg != 8) |
gc = &gc2; |
|
} |
|
|
|
if (gc->attr & GRID_ATTR_REVERSE) { |
|
if (gc->fg != 7 && gc->fg != 8) |
|
gc2.attr &= ~GRID_ATTR_REVERSE; |
gc2.attr &= ~GRID_ATTR_REVERSE; |
} else { |
} else { |
if (gc->bg != 0 && gc->bg != 8) |
if (gc2.bg != 0 && gc2.bg != 8) |
gc2.attr |= GRID_ATTR_REVERSE; |
gc2.attr |= GRID_ATTR_REVERSE; |
} |
} |
} |
} |
|
|
|
/* Fix up the colours if necessary. */ |
|
tty_check_fg(tty, &gc2); |
|
tty_check_bg(tty, &gc2); |
|
|
/* If any bits are being cleared, reset everything. */ |
/* If any bits are being cleared, reset everything. */ |
if (tc->attr & ~gc->attr) |
if (tc->attr & ~gc2.attr) |
tty_reset(tty); |
tty_reset(tty); |
|
|
/* |
/* |
* Set the colours. This may call tty_reset() (so it comes next) and |
* Set the colours. This may call tty_reset() (so it comes next) and |
* may add to (NOT remove) the desired attributes by changing new_attr. |
* may add to (NOT remove) the desired attributes by changing new_attr. |
*/ |
*/ |
new_attr = gc->attr; |
tty_colours(tty, &gc2); |
tty_colours(tty, gc, &new_attr); |
|
|
|
/* Filter out attribute bits already set. */ |
/* Filter out attribute bits already set. */ |
changed = new_attr & ~tc->attr; |
changed = gc2.attr & ~tc->attr; |
tc->attr = new_attr; |
tc->attr = gc2.attr; |
|
|
/* Set the attributes. */ |
/* Set the attributes. */ |
if (changed & GRID_ATTR_BRIGHT) |
if (changed & GRID_ATTR_BRIGHT) |
|
|
} |
} |
|
|
void |
void |
tty_colours(struct tty *tty, const struct grid_cell *gc, u_char *attr) |
tty_colours(struct tty *tty, const struct grid_cell *gc) |
{ |
{ |
struct grid_cell *tc = &tty->cell; |
struct grid_cell *tc = &tty->cell; |
u_char fg = gc->fg, bg = gc->bg, flags = gc->flags; |
u_char fg = gc->fg, bg = gc->bg, flags = gc->flags; |
|
|
/* Set the foreground colour. */ |
/* Set the foreground colour. */ |
if (!fg_default && (fg != tc->fg || |
if (!fg_default && (fg != tc->fg || |
((flags & GRID_FLAG_FG256) != (tc->flags & GRID_FLAG_FG256)))) |
((flags & GRID_FLAG_FG256) != (tc->flags & GRID_FLAG_FG256)))) |
tty_colours_fg(tty, gc, attr); |
tty_colours_fg(tty, gc); |
|
|
/* |
/* |
* Set the background colour. This must come after the foreground as |
* Set the background colour. This must come after the foreground as |
|
|
} |
} |
|
|
void |
void |
tty_colours_fg(struct tty *tty, const struct grid_cell *gc, u_char *attr) |
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_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_colours_fg(struct tty *tty, const struct grid_cell *gc) |
|
{ |
struct grid_cell *tc = &tty->cell; |
struct grid_cell *tc = &tty->cell; |
u_char fg = gc->fg; |
u_char fg = gc->fg; |
char s[32]; |
char s[32]; |
|
|
goto save_fg; |
goto save_fg; |
if (tty_try_88(tty, fg, "38") == 0) |
if (tty_try_88(tty, fg, "38") == 0) |
goto save_fg; |
goto save_fg; |
|
/* Else already handled by tty_check_fg. */ |
/* Translate to 16-colour palette, updating bold if needed. */ |
return; |
fg = colour_256to16(fg); |
|
if (fg & 8) { |
|
fg &= 7; |
|
(*attr) |= GRID_ATTR_BRIGHT; |
|
} else |
|
tty_reset(tty); /* turn off bold */ |
|
} |
} |
|
|
/* Is this an aixterm bright colour? */ |
/* Is this an aixterm bright colour? */ |
if (fg >= 90 && fg <= 97) { |
if (fg >= 90 && fg <= 97) { |
/* 16 colour terminals or above only. */ |
xsnprintf(s, sizeof s, "\033[%dm", fg); |
if (tty_term_number(tty->term, TTYC_COLORS) >= 16) { |
tty_puts(tty, s); |
xsnprintf(s, sizeof s, "\033[%dm", fg); |
goto save_fg; |
tty_puts(tty, s); |
|
goto save_fg; |
|
} |
|
fg -= 90; |
|
(*attr) |= GRID_ATTR_BRIGHT; |
|
} |
} |
|
|
/* Otherwise set the foreground colour. */ |
/* Otherwise set the foreground colour. */ |
|
|
goto save_bg; |
goto save_bg; |
if (tty_try_88(tty, bg, "48") == 0) |
if (tty_try_88(tty, bg, "48") == 0) |
goto save_bg; |
goto save_bg; |
|
/* Else already handled by tty_check_bg. */ |
/* |
return; |
* Translate to 16-colour palette. Bold background doesn't |
|
* exist portably, so just discard the bold bit if set. |
|
*/ |
|
bg = colour_256to16(bg); |
|
if (bg & 8) |
|
bg &= 7; |
|
} |
} |
|
|
/* Is this an aixterm bright colour? */ |
/* Is this an aixterm bright colour? */ |