diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-10-09 22:00:33 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-10-09 22:00:33 +0000 |
commit | 0ba0fd389c211c35958a383cbaea138f6eebea91 (patch) | |
tree | b50b85185977a0a30d63654fb30bd389af42ebb7 | |
parent | 185f7297e8df1399094b7e3d1314f1af1e94e633 (diff) | |
download | rtmux-0ba0fd389c211c35958a383cbaea138f6eebea91.tar.gz rtmux-0ba0fd389c211c35958a383cbaea138f6eebea91.tar.bz2 rtmux-0ba0fd389c211c35958a383cbaea138f6eebea91.zip |
Translate 256 colours to 16.
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | colour.c | 27 | ||||
-rw-r--r-- | tmux.h | 3 | ||||
-rw-r--r-- | tty.c | 30 |
4 files changed, 49 insertions, 14 deletions
@@ -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 $ @@ -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]); +} @@ -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; @@ -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 && |