Translate 256 colours to 16.

This commit is contained in:
Nicholas Marriott 2008-10-09 22:00:33 +00:00
parent 185f7297e8
commit 0ba0fd389c
4 changed files with 49 additions and 14 deletions

View File

@ -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 $

View File

@ -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]);
}

3
tmux.h
View File

@ -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;

30
tty.c
View File

@ -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 &&