Mercurial > vim
comparison src/syntax.c @ 11822:1e237c5994fc v8.0.0791
patch 8.0.0791: terminal colors depend on the system
commit https://github.com/vim/vim/commit/b41bf8e6b45a773456031954bca1bc4212cbffbe
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 28 15:11:38 2017 +0200
patch 8.0.0791: terminal colors depend on the system
Problem: Terminal colors depend on the system.
Solution: Use the highlight color lookup tables.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 28 Jul 2017 15:15:04 +0200 |
parents | 12fa6072977a |
children | 318ae82d8ba4 |
comparison
equal
deleted
inserted
replaced
11821:5a00d6370ba3 | 11822:1e237c5994fc |
---|---|
7219 recursive = FALSE; | 7219 recursive = FALSE; |
7220 | 7220 |
7221 return retval; | 7221 return retval; |
7222 } | 7222 } |
7223 | 7223 |
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 | |
7224 /* | 7334 /* |
7225 * Handle the ":highlight .." command. | 7335 * Handle the ":highlight .." command. |
7226 * When using ":hi clear" this is called recursively for each group with | 7336 * When using ":hi clear" this is called recursively for each group with |
7227 * "forceit" and "init" both TRUE. | 7337 * "forceit" and "init" both TRUE. |
7228 */ | 7338 */ |
7721 break; | 7831 break; |
7722 } | 7832 } |
7723 } | 7833 } |
7724 else | 7834 else |
7725 { | 7835 { |
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}; | |
7765 #if defined(__QNXNTO__) | 7836 #if defined(__QNXNTO__) |
7766 static int *color_numbers_8_qansi = color_numbers_8; | 7837 static int *color_numbers_8_qansi = color_numbers_8; |
7767 /* On qnx, the 8 & 16 color arrays are the same */ | 7838 /* On qnx, the 8 & 16 color arrays are the same */ |
7768 if (STRNCMP(T_NAME, "qansi", 5) == 0) | 7839 if (STRNCMP(T_NAME, "qansi", 5) == 0) |
7769 color_numbers_8_qansi = color_numbers_16; | 7840 color_numbers_8_qansi = color_numbers_16; |
7780 EMSG2(_("E421: Color name or number not recognized: %s"), key_start); | 7851 EMSG2(_("E421: Color name or number not recognized: %s"), key_start); |
7781 error = TRUE; | 7852 error = TRUE; |
7782 break; | 7853 break; |
7783 } | 7854 } |
7784 | 7855 |
7785 /* Use the _16 table to check if it's a valid color name. */ | 7856 color = lookup_color(i, key[5] == 'F'); |
7786 color = color_numbers_16[i]; | 7857 } |
7787 if (color >= 0) | 7858 |
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 } | |
7835 } | |
7836 /* Add one to the argument, to avoid zero. Zero is used for | 7859 /* Add one to the argument, to avoid zero. Zero is used for |
7837 * "NONE", then "color" is -1. */ | 7860 * "NONE", then "color" is -1. */ |
7838 if (key[5] == 'F') | 7861 if (key[5] == 'F') |
7839 { | 7862 { |
7840 HL_TABLE()[idx].sg_cterm_fg = color + 1; | 7863 HL_TABLE()[idx].sg_cterm_fg = color + 1; |