Using colors from the 256-color set is a bit annoying at times because
tmux only accepts the British spelling "colour123" where xterm uses
"color123" and Emacs (which has the very useful M-x list-colors-display)
uses "color-123".

To make customization less frustrating, accept all variants as input
while still using the original spelling for output (used in
show-options).

(Nicholas, please reindent the local variables as necessary.)

diff --git a/colour.c b/colour.c
index da1cb42..f207986 100644
--- a/colour.c
+++ b/colour.c
@@ -39,6 +39,11 @@ struct colour_rgb {
 /* 256 colour RGB table, generated on first use. */
 struct colour_rgb *colour_rgb_256;
 
+/* Alternative spellings. */
+const char *colour_spellings[] = {
+       "colour-", "colour", "color-", "color", NULL
+};
+
 void   colour_rgb_generate256(void);
 u_int  colour_rgb_distance(struct colour_rgb *, struct colour_rgb *);
 int    colour_rgb_find(struct colour_rgb *);
@@ -198,6 +203,7 @@ colour_fromstring(const char *s)
        const char              *cp;
        struct colour_rgb        rgb;
        int                      n;
+       const char              **sp;
 
        if (*s == '#' && strlen(s) == 7) {
                for (cp = s + 1; isxdigit((u_char) *cp); cp++)
@@ -210,11 +216,13 @@ colour_fromstring(const char *s)
                return (colour_rgb_find(&rgb) | 0x100);
        }
 
-       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);
+       for (sp = colour_spellings; *sp != NULL; sp++) {
+               if (strncasecmp(s, *sp, strlen(*sp)) == 0) {
+                       n = strtonum(s + strlen(*sp), 0, 255, &errstr);
+                       if (errstr != NULL)
+                               return (-1);
+                       return (n | 0x100);
+               }
        }
 
        if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0'))

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to