aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--colour.c27
-rw-r--r--tmux.h3
-rw-r--r--tty.c30
4 files changed, 49 insertions, 14 deletions
diff --git a/CHANGES b/CHANGES
index e49b1a42..3bcfd283 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,6 @@
09 October 2008
+* Translate 256 colours into 16 if 256 is not available, same as screen does.
* Better support for OSC command (only to set window title now), and also
support using APC for the same purpose (some Linux default shell profiles do
this).
@@ -680,4 +681,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.163 2008-10-09 21:22:16 nicm Exp $
+$Id: CHANGES,v 1.164 2008-10-09 22:00:33 nicm Exp $
diff --git a/colour.c b/colour.c
index 36a2cf6f..552a220c 100644
--- a/colour.c
+++ b/colour.c
@@ -1,4 +1,4 @@
-/* $Id: colour.c,v 1.1 2008-09-10 18:59:29 nicm Exp $ */
+/* $Id: colour.c,v 1.2 2008-10-09 22:00:33 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -72,3 +72,28 @@ colour_fromstring(const char *s)
return (8);
return (255);
}
+
+u_char
+colour_translate256(u_char c)
+{
+ static const u_char table[] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 0, 4, 4, 4, 12, 12, 2, 6, 4, 4, 12, 12, 2, 2, 6, 4,
+ 12, 12, 2, 2, 2, 6, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10,
+ 10, 10, 10, 14, 1, 5, 4, 4, 12, 12, 3, 8, 4, 4, 12, 12,
+ 2, 2, 6, 4, 12, 12, 2, 2, 2, 6, 12, 12, 10, 10, 10, 10,
+ 14, 12, 10, 10, 10, 10, 10, 14, 1, 1, 5, 4, 12, 12, 1, 1,
+ 5, 4, 12, 12, 3, 3, 8, 4, 12, 12, 2, 2, 2, 6, 12, 12,
+ 10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14, 1, 1, 1, 5,
+ 12, 12, 1, 1, 1, 5, 12, 12, 1, 1, 1, 5, 12, 12, 3, 3,
+ 3, 7, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14,
+ 9, 9, 9, 9, 13, 12, 9, 9, 9, 9, 13, 12, 9, 9, 9, 9,
+ 13, 12, 9, 9, 9, 9, 13, 12, 11, 11, 11, 11, 7, 12, 10, 10,
+ 10, 10, 10, 14, 9, 9, 9, 9, 9, 13, 9, 9, 9, 9, 9, 13,
+ 9, 9, 9, 9, 9, 13, 9, 9, 9, 9, 9, 13, 9, 9, 9, 9,
+ 9, 13, 11, 11, 11, 11, 11, 15, 0, 0, 0, 0, 0, 0, 8, 8,
+ 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15
+ };
+
+ return (table[c]);
+}
diff --git a/tmux.h b/tmux.h
index a1d48698..cd95fb9f 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.192 2008-10-09 21:22:16 nicm Exp $ */
+/* $Id: tmux.h,v 1.193 2008-10-09 22:00:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1136,6 +1136,7 @@ void input_key(struct window *, int);
/* colour.c */
const char *colour_tostring(u_char);
u_char colour_fromstring(const char *);
+u_char colour_translate256(u_char);
/* grid.c */
extern const struct grid_cell grid_default_cell;
diff --git a/tty.c b/tty.c
index 2df880af..6477cbde 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $Id: tty.c,v 1.45 2008-09-26 07:23:21 nicm Exp $ */
+/* $Id: tty.c,v 1.46 2008-10-09 22:00:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -980,11 +980,14 @@ tty_attributes_fg(struct tty *tty, const struct grid_cell *gc)
tty_puts(tty, s);
return;
}
-
- if (fg > 15)
- fg = 8;
- else if (fg > 7)
- fg -= 8;
+ fg = colour_translate256(fg);
+ if (fg & 8) {
+ fg &= 7;
+ if (enter_bold_mode != NULL)
+ tty_puts(tty, enter_bold_mode);
+ tty->cell.attr |= GRID_ATTR_BRIGHT;
+ } else if (tty->cell.attr & GRID_ATTR_BRIGHT)
+ tty_reset(tty);
}
if (fg == 8 &&
@@ -1010,11 +1013,16 @@ tty_attributes_bg(struct tty *tty, const struct grid_cell *gc)
tty_puts(tty, s);
return;
}
-
- if (bg > 15)
- bg = 8;
- else if (bg > 7)
- bg -= 8;
+ bg = colour_translate256(bg);
+ if (bg & 8) {
+ /*
+ * Bold background; not sure how widely this is
+ * supported...
+ */
+ xsnprintf(s, sizeof s, "\033[%hhum", 92 + bg);
+ tty_puts(tty, s);
+ return;
+ }
}
if (bg == 8 &&