If colours are not supported by the terminal, try to emulate a coloured

background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.
pull/1/head
Nicholas Marriott 2009-08-05 16:26:38 +00:00
parent 12ef3ceda1
commit bcddddf98d
7 changed files with 39 additions and 25 deletions

View File

@ -64,8 +64,8 @@ status_redraw(struct client *c)
if (gettimeofday(&c->status_timer, NULL) != 0)
fatal("gettimeofday");
memcpy(&stdgc, &grid_default_cell, sizeof gc);
stdgc.bg = options_get_number(&s->options, "status-fg");
stdgc.fg = options_get_number(&s->options, "status-bg");
stdgc.fg = options_get_number(&s->options, "status-fg");
stdgc.bg = options_get_number(&s->options, "status-bg");
stdgc.attr |= options_get_number(&s->options, "status-attr");
yy = c->tty.sy - 1;
@ -563,8 +563,8 @@ status_message_redraw(struct client *c)
len = c->tty.sx;
memcpy(&gc, &grid_default_cell, sizeof gc);
gc.bg = options_get_number(&s->options, "message-fg");
gc.fg = options_get_number(&s->options, "message-bg");
gc.fg = options_get_number(&s->options, "message-fg");
gc.bg = options_get_number(&s->options, "message-bg");
gc.attr |= options_get_number(&s->options, "message-attr");
screen_write_start(&ctx, NULL, &c->status);
@ -662,8 +662,8 @@ status_prompt_redraw(struct client *c)
len = c->tty.sx;
memcpy(&gc, &grid_default_cell, sizeof gc);
gc.bg = options_get_number(&s->options, "message-fg");
gc.fg = options_get_number(&s->options, "message-bg");
gc.fg = options_get_number(&s->options, "message-fg");
gc.bg = options_get_number(&s->options, "message-bg");
gc.attr |= options_get_number(&s->options, "message-attr");
screen_write_start(&ctx, NULL, &c->status);

6
tmux.c
View File

@ -345,7 +345,7 @@ main(int argc, char **argv)
options_set_number(&global_s_options, "display-time", 750);
options_set_number(&global_s_options, "history-limit", 2000);
options_set_number(&global_s_options, "lock-after-time", 0);
options_set_number(&global_s_options, "message-attr", GRID_ATTR_REVERSE);
options_set_number(&global_s_options, "message-attr", 0);
options_set_number(&global_s_options, "message-bg", 3);
options_set_number(&global_s_options, "message-fg", 0);
options_set_number(&global_s_options, "prefix", '\002');
@ -353,7 +353,7 @@ main(int argc, char **argv)
options_set_number(&global_s_options, "set-remain-on-exit", 0);
options_set_number(&global_s_options, "set-titles", 0);
options_set_number(&global_s_options, "status", 1);
options_set_number(&global_s_options, "status-attr", GRID_ATTR_REVERSE);
options_set_number(&global_s_options, "status-attr", 0);
options_set_number(&global_s_options, "status-bg", 2);
options_set_number(&global_s_options, "status-fg", 0);
options_set_number(&global_s_options, "status-interval", 15);
@ -383,7 +383,7 @@ main(int argc, char **argv)
options_set_number(&global_w_options, "force-width", 0);
options_set_number(&global_w_options, "main-pane-width", 81);
options_set_number(&global_w_options, "main-pane-height", 24);
options_set_number(&global_w_options, "mode-attr", GRID_ATTR_REVERSE);
options_set_number(&global_w_options, "mode-attr", 0);
options_set_number(&global_w_options, "mode-bg", 3);
options_set_number(&global_w_options, "mode-fg", 0);
options_set_number(&global_w_options, "mode-keys", MODEKEY_EMACS);

26
tty.c
View File

@ -951,19 +951,33 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc)
{
struct grid_cell *tc = &tty->cell;
u_char changed;
u_int fg, bg;
u_int fg, bg, attr;
/*
* If no setab, try to use the reverse attribute as a best-effort for a
* non-default background. This is a bit of a hack but it doesn't do
* any serious harm and makes a couple of applications happier.
*/
fg = gc->fg; bg = gc->bg; attr = gc->attr;
if (!tty_term_has(tty->term, TTYC_SETAB)) {
if (attr & GRID_ATTR_REVERSE) {
if (fg != 7 && fg != 8)
attr &= ~GRID_ATTR_REVERSE;
} else {
if (bg != 0 && bg != 8)
attr |= GRID_ATTR_REVERSE;
}
}
/* If any bits are being cleared, reset everything. */
if (tc->attr & ~gc->attr)
if (tc->attr & ~attr)
tty_reset(tty);
/* Filter out attribute bits already set. */
changed = gc->attr & ~tc->attr;
tc->attr = gc->attr;
changed = attr & ~tc->attr;
tc->attr = attr;
/* Set the attributes. */
fg = gc->fg;
bg = gc->bg;
if (changed & GRID_ATTR_BRIGHT)
tty_putcode(tty, TTYC_BOLD);
if (changed & GRID_ATTR_DIM)

View File

@ -305,8 +305,8 @@ window_choose_write_line(
utf8flag = options_get_number(&wp->window->options, "utf8");
memcpy(&gc, &grid_default_cell, sizeof gc);
if (data->selected == data->top + py) {
gc.fg = options_get_number(&wp->window->options, "mode-bg");
gc.bg = options_get_number(&wp->window->options, "mode-fg");
gc.fg = options_get_number(&wp->window->options, "mode-fg");
gc.bg = options_get_number(&wp->window->options, "mode-bg");
gc.attr |= options_get_number(&wp->window->options, "mode-attr");
}

View File

@ -264,8 +264,8 @@ window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, u_i
memcpy(&gc, &grid_default_cell, sizeof gc);
size = xsnprintf(hdr, sizeof hdr,
"[%u,%u/%u]", data->ox, data->oy, screen_hsize(&wp->base));
gc.bg = options_get_number(&wp->window->options, "mode-fg");
gc.fg = options_get_number(&wp->window->options, "mode-bg");
gc.fg = options_get_number(&wp->window->options, "mode-fg");
gc.bg = options_get_number(&wp->window->options, "mode-bg");
gc.attr |= options_get_number(&wp->window->options, "mode-attr");
screen_write_cursormove(ctx, screen_size_x(s) - size, 0);
screen_write_puts(ctx, &gc, "%s", hdr);
@ -368,8 +368,8 @@ window_copy_update_selection(struct window_pane *wp)
/* Set colours. */
memcpy(&gc, &grid_default_cell, sizeof gc);
gc.bg = options_get_number(&wp->window->options, "mode-fg");
gc.fg = options_get_number(&wp->window->options, "mode-bg");
gc.fg = options_get_number(&wp->window->options, "mode-fg");
gc.bg = options_get_number(&wp->window->options, "mode-bg");
gc.attr |= options_get_number(&wp->window->options, "mode-attr");
/* Find top-left of screen. */

View File

@ -176,8 +176,8 @@ window_more_write_line(
size = xsnprintf(hdr, sizeof hdr,
"[%u/%u]", data->top, ARRAY_LENGTH(&data->list));
screen_write_cursormove(ctx, screen_size_x(s) - size, 0);
gc.bg = options_get_number(&wp->window->options, "mode-fg");
gc.fg = options_get_number(&wp->window->options, "mode-bg");
gc.fg = options_get_number(&wp->window->options, "mode-fg");
gc.bg = options_get_number(&wp->window->options, "mode-bg");
gc.attr |= options_get_number(&wp->window->options, "mode-attr");
screen_write_puts(ctx, &gc, "%s", hdr);
memcpy(&gc, &grid_default_cell, sizeof gc);

View File

@ -176,8 +176,8 @@ window_scroll_write_line(
memcpy(&gc, &grid_default_cell, sizeof gc);
size = xsnprintf(hdr, sizeof hdr,
"[%u,%u/%u]", data->ox, data->oy, screen_hsize(&wp->base));
gc.bg = options_get_number(&wp->window->options, "mode-fg");
gc.fg = options_get_number(&wp->window->options, "mode-bg");
gc.fg = options_get_number(&wp->window->options, "mode-fg");
gc.bg = options_get_number(&wp->window->options, "mode-bg");
gc.attr |= options_get_number(&wp->window->options, "mode-attr");
screen_write_cursormove(ctx, screen_size_x(s) - size, 0);
screen_write_puts(ctx, &gc, "%s", hdr);