@@ -7221,6 +7221,116 @@ load_colors(char_u *name)
72217221 return retval ;
72227222}
72237223
7224+ static char * (color_names [28 ]) = {
7225+ "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan" ,
7226+ "DarkRed" , "DarkMagenta" , "Brown" , "DarkYellow" ,
7227+ "Gray" , "Grey" , "LightGray" , "LightGrey" ,
7228+ "DarkGray" , "DarkGrey" ,
7229+ "Blue" , "LightBlue" , "Green" , "LightGreen" ,
7230+ "Cyan" , "LightCyan" , "Red" , "LightRed" , "Magenta" ,
7231+ "LightMagenta" , "Yellow" , "LightYellow" , "White" , "NONE" };
7232+ /* indices:
7233+ * 0, 1, 2, 3,
7234+ * 4, 5, 6, 7,
7235+ * 8, 9, 10, 11,
7236+ * 12, 13,
7237+ * 14, 15, 16, 17,
7238+ * 18, 19, 20, 21, 22,
7239+ * 23, 24, 25, 26, 27 */
7240+ static int color_numbers_16 [28 ] = {0 , 1 , 2 , 3 ,
7241+ 4 , 5 , 6 , 6 ,
7242+ 7 , 7 , 7 , 7 ,
7243+ 8 , 8 ,
7244+ 9 , 9 , 10 , 10 ,
7245+ 11 , 11 , 12 , 12 , 13 ,
7246+ 13 , 14 , 14 , 15 , -1 };
7247+ /* for xterm with 88 colors... */
7248+ static int color_numbers_88 [28 ] = {0 , 4 , 2 , 6 ,
7249+ 1 , 5 , 32 , 72 ,
7250+ 84 , 84 , 7 , 7 ,
7251+ 82 , 82 ,
7252+ 12 , 43 , 10 , 61 ,
7253+ 14 , 63 , 9 , 74 , 13 ,
7254+ 75 , 11 , 78 , 15 , -1 };
7255+ /* for xterm with 256 colors... */
7256+ static int color_numbers_256 [28 ] = {0 , 4 , 2 , 6 ,
7257+ 1 , 5 , 130 , 130 ,
7258+ 248 , 248 , 7 , 7 ,
7259+ 242 , 242 ,
7260+ 12 , 81 , 10 , 121 ,
7261+ 14 , 159 , 9 , 224 , 13 ,
7262+ 225 , 11 , 229 , 15 , -1 };
7263+ /* for terminals with less than 16 colors... */
7264+ static int color_numbers_8 [28 ] = {0 , 4 , 2 , 6 ,
7265+ 1 , 5 , 3 , 3 ,
7266+ 7 , 7 , 7 , 7 ,
7267+ 0 + 8 , 0 + 8 ,
7268+ 4 + 8 , 4 + 8 , 2 + 8 , 2 + 8 ,
7269+ 6 + 8 , 6 + 8 , 1 + 8 , 1 + 8 , 5 + 8 ,
7270+ 5 + 8 , 3 + 8 , 3 + 8 , 7 + 8 , -1 };
7271+
7272+ /*
7273+ * Lookup the "cterm" value to be used for color with index "idx" in
7274+ * color_names[].
7275+ */
7276+ int
7277+ lookup_color (int idx , int foreground )
7278+ {
7279+ int color = color_numbers_16 [idx ];
7280+ char_u * p ;
7281+
7282+ /* Use the _16 table to check if it's a valid color name. */
7283+ if (color < 0 )
7284+ return -1 ;
7285+
7286+ if (t_colors == 8 )
7287+ {
7288+ /* t_Co is 8: use the 8 colors table */
7289+ #if defined(__QNXNTO__ )
7290+ color = color_numbers_8_qansi [idx ];
7291+ #else
7292+ color = color_numbers_8 [idx ];
7293+ #endif
7294+ if (foreground )
7295+ {
7296+ /* set/reset bold attribute to get light foreground
7297+ * colors (on some terminals, e.g. "linux") */
7298+ if (color & 8 )
7299+ {
7300+ HL_TABLE ()[idx ].sg_cterm |= HL_BOLD ;
7301+ HL_TABLE ()[idx ].sg_cterm_bold = TRUE;
7302+ }
7303+ else
7304+ HL_TABLE ()[idx ].sg_cterm &= ~HL_BOLD ;
7305+ }
7306+ color &= 7 ; /* truncate to 8 colors */
7307+ }
7308+ else if (t_colors == 16 || t_colors == 88
7309+ || t_colors >= 256 )
7310+ {
7311+ /*
7312+ * Guess: if the termcap entry ends in 'm', it is
7313+ * probably an xterm-like terminal. Use the changed
7314+ * order for colors.
7315+ */
7316+ if (* T_CAF != NUL )
7317+ p = T_CAF ;
7318+ else
7319+ p = T_CSF ;
7320+ if (* p != NUL && (t_colors > 256
7321+ || * (p + STRLEN (p ) - 1 ) == 'm' ))
7322+ {
7323+ if (t_colors == 88 )
7324+ color = color_numbers_88 [idx ];
7325+ else if (t_colors >= 256 )
7326+ color = color_numbers_256 [idx ];
7327+ else
7328+ color = color_numbers_8 [idx ];
7329+ }
7330+ }
7331+ return color ;
7332+ }
7333+
72247334/*
72257335 * Handle the ":highlight .." command.
72267336 * When using ":hi clear" this is called recursively for each group with
@@ -7723,45 +7833,6 @@ do_highlight(
77237833 }
77247834 else
77257835 {
7726- static char * (color_names [28 ]) = {
7727- "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan" ,
7728- "DarkRed" , "DarkMagenta" , "Brown" , "DarkYellow" ,
7729- "Gray" , "Grey" ,
7730- "LightGray" , "LightGrey" , "DarkGray" , "DarkGrey" ,
7731- "Blue" , "LightBlue" , "Green" , "LightGreen" ,
7732- "Cyan" , "LightCyan" , "Red" , "LightRed" , "Magenta" ,
7733- "LightMagenta" , "Yellow" , "LightYellow" , "White" , "NONE" };
7734- static int color_numbers_16 [28 ] = {0 , 1 , 2 , 3 ,
7735- 4 , 5 , 6 , 6 ,
7736- 7 , 7 ,
7737- 7 , 7 , 8 , 8 ,
7738- 9 , 9 , 10 , 10 ,
7739- 11 , 11 , 12 , 12 , 13 ,
7740- 13 , 14 , 14 , 15 , -1 };
7741- /* for xterm with 88 colors... */
7742- static int color_numbers_88 [28 ] = {0 , 4 , 2 , 6 ,
7743- 1 , 5 , 32 , 72 ,
7744- 84 , 84 ,
7745- 7 , 7 , 82 , 82 ,
7746- 12 , 43 , 10 , 61 ,
7747- 14 , 63 , 9 , 74 , 13 ,
7748- 75 , 11 , 78 , 15 , -1 };
7749- /* for xterm with 256 colors... */
7750- static int color_numbers_256 [28 ] = {0 , 4 , 2 , 6 ,
7751- 1 , 5 , 130 , 130 ,
7752- 248 , 248 ,
7753- 7 , 7 , 242 , 242 ,
7754- 12 , 81 , 10 , 121 ,
7755- 14 , 159 , 9 , 224 , 13 ,
7756- 225 , 11 , 229 , 15 , -1 };
7757- /* for terminals with less than 16 colors... */
7758- static int color_numbers_8 [28 ] = {0 , 4 , 2 , 6 ,
7759- 1 , 5 , 3 , 3 ,
7760- 7 , 7 ,
7761- 7 , 7 , 0 + 8 , 0 + 8 ,
7762- 4 + 8 , 4 + 8 , 2 + 8 , 2 + 8 ,
7763- 6 + 8 , 6 + 8 , 1 + 8 , 1 + 8 , 5 + 8 ,
7764- 5 + 8 , 3 + 8 , 3 + 8 , 7 + 8 , -1 };
77657836#if defined(__QNXNTO__ )
77667837 static int * color_numbers_8_qansi = color_numbers_8 ;
77677838 /* On qnx, the 8 & 16 color arrays are the same */
@@ -7782,57 +7853,9 @@ do_highlight(
77827853 break ;
77837854 }
77847855
7785- /* Use the _16 table to check if it's a valid color name. */
7786- color = color_numbers_16 [i ];
7787- if (color >= 0 )
7788- {
7789- if (t_colors == 8 )
7790- {
7791- /* t_Co is 8: use the 8 colors table */
7792- #if defined(__QNXNTO__ )
7793- color = color_numbers_8_qansi [i ];
7794- #else
7795- color = color_numbers_8 [i ];
7796- #endif
7797- if (key [5 ] == 'F' )
7798- {
7799- /* set/reset bold attribute to get light foreground
7800- * colors (on some terminals, e.g. "linux") */
7801- if (color & 8 )
7802- {
7803- HL_TABLE ()[idx ].sg_cterm |= HL_BOLD ;
7804- HL_TABLE ()[idx ].sg_cterm_bold = TRUE;
7805- }
7806- else
7807- HL_TABLE ()[idx ].sg_cterm &= ~HL_BOLD ;
7808- }
7809- color &= 7 ; /* truncate to 8 colors */
7810- }
7811- else if (t_colors == 16 || t_colors == 88
7812- || t_colors >= 256 )
7813- {
7814- /*
7815- * Guess: if the termcap entry ends in 'm', it is
7816- * probably an xterm-like terminal. Use the changed
7817- * order for colors.
7818- */
7819- if (* T_CAF != NUL )
7820- p = T_CAF ;
7821- else
7822- p = T_CSF ;
7823- if (* p != NUL && (t_colors > 256
7824- || * (p + STRLEN (p ) - 1 ) == 'm' ))
7825- {
7826- if (t_colors == 88 )
7827- color = color_numbers_88 [i ];
7828- else if (t_colors >= 256 )
7829- color = color_numbers_256 [i ];
7830- else
7831- color = color_numbers_8 [i ];
7832- }
7833- }
7834- }
7856+ color = lookup_color (i , key [5 ] == 'F' );
78357857 }
7858+
78367859 /* Add one to the argument, to avoid zero. Zero is used for
78377860 * "NONE", then "color" is -1. */
78387861 if (key [5 ] == 'F' )
0 commit comments