=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/colour.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/tmux/colour.c 2009/06/01 22:58:49 1.1 --- src/usr.bin/tmux/colour.c 2009/09/10 17:16:24 1.2 *************** *** 1,4 **** ! /* $OpenBSD: colour.c,v 1.1 2009/06/01 22:58:49 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: colour.c,v 1.2 2009/09/10 17:16:24 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 18,30 **** #include #include #include "tmux.h" const char * ! colour_tostring(u_char c) { switch (c) { case 0: return ("black"); --- 18,59 ---- #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(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,56 **** --- 80,95 ---- 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'))