mirror of
https://github.com/vim/vim.git
synced 2025-09-29 04:34:16 -04:00
patch 8.2.3562: cannot add color names
Problem: Cannot add color names. Solution: Add the v:colornames dictionary. (Drew Vogel, closes #8761)
This commit is contained in:
committed by
Bram Moolenaar
parent
3c5904d2a5
commit
e30d10253f
159
src/gui_haiku.cc
159
src/gui_haiku.cc
@@ -4054,164 +4054,7 @@ guicolor_T
|
||||
gui_mch_get_color(
|
||||
char_u *name)
|
||||
{
|
||||
typedef struct GuiColourTable
|
||||
{
|
||||
const char *name;
|
||||
guicolor_T colour;
|
||||
} GuiColourTable;
|
||||
|
||||
#define NSTATIC_COLOURS 50 // 32
|
||||
#define NDYNAMIC_COLOURS 33
|
||||
#define NCOLOURS (NSTATIC_COLOURS + NDYNAMIC_COLOURS)
|
||||
|
||||
static GuiColourTable table[NCOLOURS] =
|
||||
{
|
||||
{"Black", RGB(0x00, 0x00, 0x00)},
|
||||
{"DarkGray", RGB(0x80, 0x80, 0x80)},
|
||||
{"DarkGrey", RGB(0x80, 0x80, 0x80)},
|
||||
{"Gray", RGB(0xC0, 0xC0, 0xC0)},
|
||||
{"Grey", RGB(0xC0, 0xC0, 0xC0)},
|
||||
{"LightGray", RGB(0xD3, 0xD3, 0xD3)},
|
||||
{"LightGrey", RGB(0xD3, 0xD3, 0xD3)},
|
||||
{"Gray10", RGB(0x1A, 0x1A, 0x1A)},
|
||||
{"Grey10", RGB(0x1A, 0x1A, 0x1A)},
|
||||
{"Gray20", RGB(0x33, 0x33, 0x33)},
|
||||
{"Grey20", RGB(0x33, 0x33, 0x33)},
|
||||
{"Gray30", RGB(0x4D, 0x4D, 0x4D)},
|
||||
{"Grey30", RGB(0x4D, 0x4D, 0x4D)},
|
||||
{"Gray40", RGB(0x66, 0x66, 0x66)},
|
||||
{"Grey40", RGB(0x66, 0x66, 0x66)},
|
||||
{"Gray50", RGB(0x7F, 0x7F, 0x7F)},
|
||||
{"Grey50", RGB(0x7F, 0x7F, 0x7F)},
|
||||
{"Gray60", RGB(0x99, 0x99, 0x99)},
|
||||
{"Grey60", RGB(0x99, 0x99, 0x99)},
|
||||
{"Gray70", RGB(0xB3, 0xB3, 0xB3)},
|
||||
{"Grey70", RGB(0xB3, 0xB3, 0xB3)},
|
||||
{"Gray80", RGB(0xCC, 0xCC, 0xCC)},
|
||||
{"Grey80", RGB(0xCC, 0xCC, 0xCC)},
|
||||
{"Gray90", RGB(0xE5, 0xE5, 0xE5)},
|
||||
{"Grey90", RGB(0xE5, 0xE5, 0xE5)},
|
||||
{"White", RGB(0xFF, 0xFF, 0xFF)},
|
||||
{"DarkRed", RGB(0x80, 0x00, 0x00)},
|
||||
{"Red", RGB(0xFF, 0x00, 0x00)},
|
||||
{"LightRed", RGB(0xFF, 0xA0, 0xA0)},
|
||||
{"DarkBlue", RGB(0x00, 0x00, 0x80)},
|
||||
{"Blue", RGB(0x00, 0x00, 0xFF)},
|
||||
{"LightBlue", RGB(0xA0, 0xA0, 0xFF)},
|
||||
{"DarkGreen", RGB(0x00, 0x80, 0x00)},
|
||||
{"Green", RGB(0x00, 0xFF, 0x00)},
|
||||
{"LightGreen", RGB(0xA0, 0xFF, 0xA0)},
|
||||
{"DarkCyan", RGB(0x00, 0x80, 0x80)},
|
||||
{"Cyan", RGB(0x00, 0xFF, 0xFF)},
|
||||
{"LightCyan", RGB(0xA0, 0xFF, 0xFF)},
|
||||
{"DarkMagenta", RGB(0x80, 0x00, 0x80)},
|
||||
{"Magenta", RGB(0xFF, 0x00, 0xFF)},
|
||||
{"LightMagenta", RGB(0xFF, 0xA0, 0xFF)},
|
||||
{"Brown", RGB(0x80, 0x40, 0x40)},
|
||||
{"Yellow", RGB(0xFF, 0xFF, 0x00)},
|
||||
{"LightYellow", RGB(0xFF, 0xFF, 0xA0)},
|
||||
{"DarkYellow", RGB(0xBB, 0xBB, 0x00)},
|
||||
{"SeaGreen", RGB(0x2E, 0x8B, 0x57)},
|
||||
{"Orange", RGB(0xFF, 0xA5, 0x00)},
|
||||
{"Purple", RGB(0xA0, 0x20, 0xF0)},
|
||||
{"SlateBlue", RGB(0x6A, 0x5A, 0xCD)},
|
||||
{"Violet", RGB(0xEE, 0x82, 0xEE)},
|
||||
// NOTE: some entries are zero-allocated for NDDYNAMIC_COLORS
|
||||
// in this table!
|
||||
};
|
||||
|
||||
static int endColour = NSTATIC_COLOURS;
|
||||
static int newColour = NSTATIC_COLOURS;
|
||||
|
||||
int r, g, b;
|
||||
int i;
|
||||
|
||||
if (name[0] == '#' && STRLEN(name) == 7)
|
||||
{
|
||||
// Name is in "#rrggbb" format
|
||||
r = hex_digit(name[1]) * 16 + hex_digit(name[2]);
|
||||
g = hex_digit(name[3]) * 16 + hex_digit(name[4]);
|
||||
b = hex_digit(name[5]) * 16 + hex_digit(name[6]);
|
||||
if (r < 0 || g < 0 || b < 0)
|
||||
return INVALCOLOR;
|
||||
return RGB(r, g, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if the name is one of the colours we know
|
||||
for (i = 0; i < endColour; i++)
|
||||
if (STRICMP(name, table[i].name) == 0)
|
||||
return table[i].colour;
|
||||
}
|
||||
|
||||
/*
|
||||
* Last attempt. Look in the file "$VIMRUNTIME/rgb.txt".
|
||||
*/
|
||||
{
|
||||
#define LINE_LEN 100
|
||||
FILE *fd;
|
||||
char line[LINE_LEN];
|
||||
char_u *fname;
|
||||
|
||||
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)
|
||||
return INVALCOLOR;
|
||||
|
||||
while (!feof(fd))
|
||||
{
|
||||
int len;
|
||||
int pos;
|
||||
char *colour;
|
||||
|
||||
fgets(line, LINE_LEN, fd);
|
||||
len = strlen(line);
|
||||
|
||||
if (len <= 1 || line[len-1] != '\n')
|
||||
continue;
|
||||
|
||||
line[len-1] = '\0';
|
||||
|
||||
i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos);
|
||||
if (i != 3)
|
||||
continue;
|
||||
|
||||
colour = line + pos;
|
||||
|
||||
if (STRICMP(colour, name) == 0)
|
||||
{
|
||||
fclose(fd);
|
||||
/*
|
||||
* Now remember this colour in the table.
|
||||
* A LRU scheme might be better but this is simpler.
|
||||
* Or could use a growing array.
|
||||
*/
|
||||
guicolor_T gcolour = RGB(r,g,b);
|
||||
|
||||
// NOTE: see note above in table allocation! We are working here with
|
||||
// dynamically allocated names, not constant ones!
|
||||
vim_free((char*)table[newColour].name);
|
||||
table[newColour].name = (char *)vim_strsave((char_u *)colour);
|
||||
table[newColour].colour = gcolour;
|
||||
|
||||
newColour++;
|
||||
if (newColour >= NCOLOURS)
|
||||
newColour = NSTATIC_COLOURS;
|
||||
if (endColour < NCOLOURS)
|
||||
endColour = newColour;
|
||||
|
||||
return gcolour;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
return INVALCOLOR;
|
||||
return gui_get_color_cmn(name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user