summaryrefslogtreecommitdiffstats
path: root/colour.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-09-11 14:13:52 +0000
committerTiago Cunha <tcunha@gmx.com>2009-09-11 14:13:52 +0000
commit0ec1ce005c98f4fa1813cf47e4bcc11d8cd4b523 (patch)
tree91a9f9bb7432bfaeb28b0be6c5280582b045181d /colour.c
parentf0cb57d8ac1a342c862320e30728ae2c1ea556aa (diff)
Sync OpenBSD patchset 322:
Permit options such as status-bg to be configured using the entire 256 colour palette by setting "colour0" to "colour255".
Diffstat (limited to 'colour.c')
-rw-r--r--colour.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/colour.c b/colour.c
index 2509a769..d4894c50 100644
--- a/colour.c
+++ b/colour.c
@@ -1,4 +1,4 @@
-/* $Id: colour.c,v 1.6 2009-05-18 15:42:30 nicm Exp $ */
+/* $Id: colour.c,v 1.7 2009-09-11 14:13:52 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,13 +18,42 @@
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
#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'))