summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-08-05 16:26:39 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-08-05 16:26:39 +0000
commite19f26e36db15d832209add2dad9b60eabf90a26 (patch)
tree3a0b742e6bf29c5ff12c81cafde3043a5fc676a4 /usr.bin/tmux
parentb75a713d7367ee3b5a85344d451f8e6db0fa4ddb (diff)
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.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/status.c14
-rw-r--r--usr.bin/tmux/tmux.c8
-rw-r--r--usr.bin/tmux/tty.c28
-rw-r--r--usr.bin/tmux/window-choose.c6
-rw-r--r--usr.bin/tmux/window-copy.c10
-rw-r--r--usr.bin/tmux/window-more.c6
-rw-r--r--usr.bin/tmux/window-scroll.c6
7 files changed, 46 insertions, 32 deletions
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c
index 46702b19f4e..edb74dc8134 100644
--- a/usr.bin/tmux/status.c
+++ b/usr.bin/tmux/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.22 2009/07/30 20:41:48 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.23 2009/08/05 16:26:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 692bcf91f19..0c85a59f9be 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.26 2009/08/04 10:31:28 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.27 2009/08/05 16:26:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index 270b9bae2e5..70bfd976421 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.17 2009/08/03 14:10:54 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.18 2009/08/05 16:26:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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)
diff --git a/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c
index b0d4cbe2e0a..d053556b1b7 100644
--- a/usr.bin/tmux/window-choose.c
+++ b/usr.bin/tmux/window-choose.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-choose.c,v 1.7 2009/07/30 07:04:50 nicm Exp $ */
+/* $OpenBSD: window-choose.c,v 1.8 2009/08/05 16:26:38 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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");
}
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 1024d9eb702..bcb8f957afc 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.13 2009/07/30 07:04:50 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.14 2009/08/05 16:26:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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. */
diff --git a/usr.bin/tmux/window-more.c b/usr.bin/tmux/window-more.c
index 26eb516ca54..f638faf1696 100644
--- a/usr.bin/tmux/window-more.c
+++ b/usr.bin/tmux/window-more.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-more.c,v 1.6 2009/07/28 07:03:32 nicm Exp $ */
+/* $OpenBSD: window-more.c,v 1.7 2009/08/05 16:26:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);
diff --git a/usr.bin/tmux/window-scroll.c b/usr.bin/tmux/window-scroll.c
index a0a40c2f2b2..1522ee53e54 100644
--- a/usr.bin/tmux/window-scroll.c
+++ b/usr.bin/tmux/window-scroll.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-scroll.c,v 1.5 2009/07/28 07:03:32 nicm Exp $ */
+/* $OpenBSD: window-scroll.c,v 1.6 2009/08/05 16:26:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);