On Di, 26 Apr 2016, Christian Brabandt wrote:
> On Di, 26 Apr 2016, Bram Moolenaar wrote:
> > It appears rgb.txt is re-read for every color name. Should be much
> > faster if we read it once and keep the result.
Okay, attached patch does that.
And since I was already looking into the colors, I updated the color
definition from the X11 repository
https://cgit.freedesktop.org/xorg/app/rgb/
since it included some new colors.
Best,
Christian
--
Ich stimme nicht mit dem überein was Du sagst, doch ich werde Dein
Recht, solche Lügen zu erzählen, bis in den Tod verteidigen.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/rgb.txt b/runtime/rgb.txt
index 5bc2baa..eeaadbe 100644
--- a/runtime/rgb.txt
+++ b/runtime/rgb.txt
@@ -1,4 +1,3 @@
-! $XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp $
255 250 250 snow
248 248 255 ghost white
248 248 255 GhostWhite
@@ -58,6 +57,14 @@
119 136 153 LightSlateGrey
190 190 190 gray
190 190 190 grey
+190 190 190 x11 gray
+190 190 190 X11Gray
+190 190 190 x11 grey
+190 190 190 X11Grey
+128 128 128 web gray
+128 128 128 WebGray
+128 128 128 web grey
+128 128 128 WebGrey
211 211 211 light grey
211 211 211 LightGrey
211 211 211 light gray
@@ -106,6 +113,7 @@
72 209 204 MediumTurquoise
64 224 208 turquoise
0 255 255 cyan
+ 0 255 255 aqua
224 255 255 light cyan
224 255 255 LightCyan
95 158 160 cadet blue
@@ -132,6 +140,11 @@
124 252 0 lawn green
124 252 0 LawnGreen
0 255 0 green
+ 0 255 0 lime
+ 0 255 0 x11 green
+ 0 255 0 X11Green
+ 0 128 0 web green
+ 0 128 0 WebGreen
127 255 0 chartreuse
0 250 154 medium spring green
0 250 154 MediumSpringGreen
@@ -203,11 +216,16 @@
219 112 147 pale violet red
219 112 147 PaleVioletRed
176 48 96 maroon
+176 48 96 x11 maroon
+176 48 96 X11Maroon
+128 0 0 web maroon
+128 0 0 WebMaroon
199 21 133 medium violet red
199 21 133 MediumVioletRed
208 32 144 violet red
208 32 144 VioletRed
255 0 255 magenta
+255 0 255 fuchsia
238 130 238 violet
221 160 221 plum
218 112 214 orchid
@@ -220,6 +238,10 @@
138 43 226 blue violet
138 43 226 BlueViolet
160 32 240 purple
+160 32 240 x11 purple
+160 32 240 X11Purple
+128 0 128 web purple
+128 0 128 WebPurple
147 112 219 medium purple
147 112 219 MediumPurple
216 191 216 thistle
@@ -751,3 +773,10 @@
139 0 0 DarkRed
144 238 144 light green
144 238 144 LightGreen
+220 20 60 crimson
+ 75 0 130 indigo
+128 128 0 olive
+102 51 153 rebecca purple
+102 51 153 RebeccaPurple
+192 192 192 silver
+ 0 128 128 teal
diff --git a/src/term.c b/src/term.c
index cc9d7ad..c4d2839 100644
--- a/src/term.c
+++ b/src/term.c
@@ -6085,59 +6085,15 @@ gui_get_color_cmn(char_u *name)
guicolor_T color;
};
+ /* only non X11 colors (not present in rgb.txt */
static struct rgbcolor_table_S rgb_table[] = {
- {(char_u *)"black", RGB(0x00, 0x00, 0x00)},
- {(char_u *)"blue", RGB(0x00, 0x00, 0xFF)},
- {(char_u *)"brown", RGB(0xA5, 0x2A, 0x2A)},
- {(char_u *)"cyan", RGB(0x00, 0xFF, 0xFF)},
- {(char_u *)"darkblue", RGB(0x00, 0x00, 0x8B)},
- {(char_u *)"darkcyan", RGB(0x00, 0x8B, 0x8B)},
- {(char_u *)"darkgray", RGB(0xA9, 0xA9, 0xA9)},
- {(char_u *)"darkgreen", RGB(0x00, 0x64, 0x00)},
- {(char_u *)"darkgrey", RGB(0xA9, 0xA9, 0xA9)},
- {(char_u *)"darkmagenta", RGB(0x8B, 0x00, 0x8B)},
- {(char_u *)"darkred", RGB(0x8B, 0x00, 0x00)},
{(char_u *)"darkyellow", RGB(0x8B, 0x8B, 0x00)}, /* No X11 */
- {(char_u *)"gray", RGB(0xBE, 0xBE, 0xBE)},
- {(char_u *)"gray10", RGB(0x1A, 0x1A, 0x1A)},
- {(char_u *)"gray20", RGB(0x33, 0x33, 0x33)},
- {(char_u *)"gray30", RGB(0x4D, 0x4D, 0x4D)},
- {(char_u *)"gray40", RGB(0x66, 0x66, 0x66)},
- {(char_u *)"gray50", RGB(0x7F, 0x7F, 0x7F)},
- {(char_u *)"gray60", RGB(0x99, 0x99, 0x99)},
- {(char_u *)"gray70", RGB(0xB3, 0xB3, 0xB3)},
- {(char_u *)"gray80", RGB(0xCC, 0xCC, 0xCC)},
- {(char_u *)"gray90", RGB(0xE5, 0xE5, 0xE5)},
- {(char_u *)"green", RGB(0x00, 0xFF, 0x00)},
- {(char_u *)"grey", RGB(0xBE, 0xBE, 0xBE)},
- {(char_u *)"grey10", RGB(0x1A, 0x1A, 0x1A)},
- {(char_u *)"grey20", RGB(0x33, 0x33, 0x33)},
- {(char_u *)"grey30", RGB(0x4D, 0x4D, 0x4D)},
- {(char_u *)"grey40", RGB(0x66, 0x66, 0x66)},
- {(char_u *)"grey50", RGB(0x7F, 0x7F, 0x7F)},
- {(char_u *)"grey60", RGB(0x99, 0x99, 0x99)},
- {(char_u *)"grey70", RGB(0xB3, 0xB3, 0xB3)},
- {(char_u *)"grey80", RGB(0xCC, 0xCC, 0xCC)},
- {(char_u *)"grey90", RGB(0xE5, 0xE5, 0xE5)},
- {(char_u *)"lightblue", RGB(0xAD, 0xD8, 0xE6)},
- {(char_u *)"lightcyan", RGB(0xE0, 0xFF, 0xFF)},
- {(char_u *)"lightgray", RGB(0xD3, 0xD3, 0xD3)},
- {(char_u *)"lightgreen", RGB(0x90, 0xEE, 0x90)},
- {(char_u *)"lightgrey", RGB(0xD3, 0xD3, 0xD3)},
{(char_u *)"lightmagenta", RGB(0xFF, 0x8B, 0xFF)}, /* No X11 */
{(char_u *)"lightred", RGB(0xFF, 0x8B, 0x8B)}, /* No X11 */
- {(char_u *)"lightyellow", RGB(0xFF, 0xFF, 0xE0)},
- {(char_u *)"magenta", RGB(0xFF, 0x00, 0xFF)},
- {(char_u *)"orange", RGB(0xFF, 0xA5, 0x00)},
- {(char_u *)"purple", RGB(0xA0, 0x20, 0xF0)},
- {(char_u *)"red", RGB(0xFF, 0x00, 0x00)},
- {(char_u *)"seagreen", RGB(0x2E, 0x8B, 0x57)},
- {(char_u *)"slateblue", RGB(0x6A, 0x5A, 0xCD)},
- {(char_u *)"violet", RGB(0xEE, 0x82, 0xEE)},
- {(char_u *)"white", RGB(0xFF, 0xFF, 0xFF)},
- {(char_u *)"yellow", RGB(0xFF, 0xFF, 0x00)},
};
+ static struct rgbcolor_table_S *colornames_table;
+ static int size = 0;
if (name[0] == '#' && STRLEN(name) == 7)
{
@@ -6158,44 +6114,75 @@ gui_get_color_cmn(char_u *name)
/*
* Last attempt. Look in the file "$VIM/rgb.txt".
*/
+ if (!size) /* colornames_table not yet initialized */
+ {
+ int cnt;
+ int indx = -1;
+ fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt");
+ if (fname == NULL)
+ return INVALCOLOR;
- fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt");
- if (fname == NULL)
- return INVALCOLOR;
+ fd = fopen((char *)fname, "rt");
+ vim_free(fname);
+ if (fd == NULL)
+ {
+ if (p_verbose > 1)
+ verb_msg((char_u *)_("Cannot open $VIMRUNTIME/rgb.txt"));
+ return INVALCOLOR;
+ }
- fd = fopen((char *)fname, "rt");
- vim_free(fname);
- if (fd == NULL)
- {
- if (p_verbose > 1)
- verb_msg((char_u *)_("Cannot open $VIMRUNTIME/rgb.txt"));
- return INVALCOLOR;
- }
+ for (cnt = 0; cnt < 2; cnt++)
+ {
+ if (cnt)
+ {
+ colornames_table = (struct rgbcolor_table_S *)alloc((unsigned)(sizeof(struct rgbcolor_table_S) * size));
+ if (colornames_table == NULL)
+ {
+ fclose(fd);
+ return INVALCOLOR;
+ }
+ rewind(fd);
+ }
+ size = 0;
- while (!feof(fd))
- {
- size_t len;
- int pos;
+ while (!feof(fd))
+ {
+ size_t len;
+ int pos;
- (void)fgets(line, LINE_LEN, fd);
- len = strlen(line);
+ (void)fgets(line, LINE_LEN, fd);
+ len = strlen(line);
- if (len <= 1 || line[len - 1] != '\n')
- continue;
+ if (len <= 1 || line[len - 1] != '\n')
+ continue;
- line[len - 1] = '\0';
+ line[len - 1] = '\0';
- i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos);
- if (i != 3)
- continue;
+ i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos);
+ if (i != 3)
+ continue;
- if (STRICMP(line + pos, name) == 0)
- {
- fclose(fd);
- return (guicolor_T)RGB(r, g, b);
+ if (cnt)
+ {
+ colornames_table[size].color_name = vim_strsave((char_u *)line + pos);
+ colornames_table[size].color = (guicolor_T)RGB(r, g, b);
+ if (STRICMP(line + pos, name) == 0)
+ indx = size;
+ }
+ size++;
+ }
}
+ fclose(fd);
+ if (indx >= 0)
+ return colornames_table[indx].color;
+ else
+ return INVALCOLOR;
}
- fclose(fd);
+ else
+ for (i = 0; i < size; i++)
+ if (STRICMP(name, colornames_table[i].color_name) == 0)
+ return colornames_table[i].color;
+
return INVALCOLOR;
}
#endif