summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/tty.c
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/tty.c
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/tty.c')
-rw-r--r--usr.bin/tmux/tty.c28
1 files changed, 21 insertions, 7 deletions
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)