Hi. I don't see a need for this. How frustrating is it really to have to change 
one letter? We consistently use colour, it's not like we mix the spellings.

-------- Original message --------
From: Romain Francoise <rom...@orebokech.com> 
Date: 09/06/2013  17:00  (GMT+00:00) 
To: Nicholas Marriott <nicholas.marri...@gmail.com> 
Cc: tmux-users@lists.sourceforge.net 
Subject: [PATCH] Accept alternative spellings of "colour" 
 
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'))
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to