From 372a8cb1d9c4306f74b592660b4ce394dff3e31d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 10 Sep 2009 17:16:24 +0000 Subject: Permit options such as status-bg to be configured using the entire 256 colour palette by setting "colour0" to "colour255". --- colour.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'colour.c') diff --git a/colour.c b/colour.c index 2067d0dd..5e31f815 100644 --- a/colour.c +++ b/colour.c @@ -18,13 +18,42 @@ #include +#include #include #include "tmux.h" +/* + * Colour to string conversion functions. Bit 8 of the colour means it is one + * of the 256 colour palette. + */ + +void +colour_set_fg(struct grid_cell *gc, int c) +{ + if (c & 0x100) + gc->flags |= GRID_FLAG_FG256; + gc->fg = c; +} + +void +colour_set_bg(struct grid_cell *gc, int c) +{ + if (c & 0x100) + gc->flags |= GRID_FLAG_BG256; + gc->bg = c; +} + const char * -colour_tostring(u_char c) +colour_tostring(int c) { + static char s[32]; + + if (c & 0x100) { + xsnprintf(s, sizeof s, "colour%u", c & ~0x100); + return (s); + } + switch (c) { case 0: return ("black"); @@ -51,6 +80,16 @@ colour_tostring(u_char c) int colour_fromstring(const char *s) { + const char *errstr; + int n; + + if (strncasecmp(s, "colour", (sizeof "colour") - 1) == 0) { + n = strtonum(s + (sizeof "colour") - 1, 0, 255, &errstr); + if (errstr != NULL) + return (-1); + return (n | 0x100); + } + if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0')) return (0); if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0')) -- cgit v1.2.3