comparison src/terminal.c @ 12973:418941f0df08 v8.0.1362

patch 8.0.1362: terminal window colors wrong when using Terminal highlighting commit https://github.com/vim/vim/commit/a7c54cfcf825e8e99db03f4ccdb1a32cd0714c52 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 1 21:07:20 2017 +0100 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting Problem: Terminal window colors wrong when using Terminal highlighting. Solution: Set ansi_index when setting the default color. Also cache the color index for Terminal. (Ozaki Kiichi, closes #2393)
author Christian Brabandt <cb@256bit.org>
date Fri, 01 Dec 2017 21:15:05 +0100
parents a9f6a874b64f
children fc0d4a036654
comparison
equal deleted inserted replaced
12972:8ce5ee69c0bb 12973:418941f0df08
186 186
187 /* The character that we know (or assume) that the terminal expects for the 187 /* The character that we know (or assume) that the terminal expects for the
188 * backspace key. */ 188 * backspace key. */
189 static int term_backspace_char = BS; 189 static int term_backspace_char = BS;
190 190
191 /* "Terminal" highlight group colors. */
192 static int term_default_cterm_fg = -1;
193 static int term_default_cterm_bg = -1;
191 194
192 /************************************** 195 /**************************************
193 * 1. Generic code for all systems. 196 * 1. Generic code for all systems.
194 */ 197 */
195 198
1832 int bold = MAYBE; 1835 int bold = MAYBE;
1833 int fg = color2index(&cellfg, TRUE, &bold); 1836 int fg = color2index(&cellfg, TRUE, &bold);
1834 int bg = color2index(&cellbg, FALSE, &bold); 1837 int bg = color2index(&cellbg, FALSE, &bold);
1835 1838
1836 /* Use the "Terminal" highlighting for the default colors. */ 1839 /* Use the "Terminal" highlighting for the default colors. */
1837 if (fg == 0 || bg == 0) 1840 if ((fg == 0 || bg == 0) && t_colors >= 16)
1838 { 1841 {
1839 int id = syn_name2id((char_u *)"Terminal"); 1842 if (fg == 0 && term_default_cterm_fg >= 0)
1840 1843 fg = term_default_cterm_fg + 1;
1841 if (id != 0 && t_colors >= 16) 1844 if (bg == 0 && term_default_cterm_bg >= 0)
1842 { 1845 bg = term_default_cterm_bg + 1;
1843 int cterm_fg, cterm_bg;
1844
1845 syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
1846 if (cterm_fg >= 0)
1847 fg = cterm_fg + 1;
1848 if (cterm_bg >= 0)
1849 bg = cterm_bg + 1;
1850 }
1851 } 1846 }
1852 1847
1853 /* with 8 colors set the bold attribute to get a bright foreground */ 1848 /* with 8 colors set the bold attribute to get a bright foreground */
1854 if (bold == TRUE) 1849 if (bold == TRUE)
1855 attr |= HL_BOLD; 1850 attr |= HL_BOLD;
2468 /* 216 color cube */ 2463 /* 216 color cube */
2469 idx = nr - 16; 2464 idx = nr - 16;
2470 rgb->blue = cube_value[idx % 6]; 2465 rgb->blue = cube_value[idx % 6];
2471 rgb->green = cube_value[idx / 6 % 6]; 2466 rgb->green = cube_value[idx / 6 % 6];
2472 rgb->red = cube_value[idx / 36 % 6]; 2467 rgb->red = cube_value[idx / 36 % 6];
2468 rgb->ansi_index = VTERM_ANSI_INDEX_NONE;
2473 } 2469 }
2474 else if (nr < 256) 2470 else if (nr < 256)
2475 { 2471 {
2476 /* 24 grey scale ramp */ 2472 /* 24 grey scale ramp */
2477 idx = nr - 232; 2473 idx = nr - 232;
2478 rgb->blue = grey_ramp[idx]; 2474 rgb->blue = grey_ramp[idx];
2479 rgb->green = grey_ramp[idx]; 2475 rgb->green = grey_ramp[idx];
2480 rgb->red = grey_ramp[idx]; 2476 rgb->red = grey_ramp[idx];
2477 rgb->ansi_index = VTERM_ANSI_INDEX_NONE;
2481 } 2478 }
2482 } 2479 }
2483 2480
2484 /* 2481 /*
2485 * Create a new vterm and initialize it. 2482 * Create a new vterm and initialize it.
2518 fgval = 255; 2515 fgval = 255;
2519 bgval = 0; 2516 bgval = 0;
2520 } 2517 }
2521 fg->red = fg->green = fg->blue = fgval; 2518 fg->red = fg->green = fg->blue = fgval;
2522 bg->red = bg->green = bg->blue = bgval; 2519 bg->red = bg->green = bg->blue = bgval;
2520 fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT;
2523 2521
2524 /* The "Terminal" highlight group overrules the defaults. */ 2522 /* The "Terminal" highlight group overrules the defaults. */
2525 id = syn_name2id((char_u *)"Terminal"); 2523 id = syn_name2id((char_u *)"Terminal");
2526 2524
2527 /* Use the actual color for the GUI and when 'termguicolors' is set. */ 2525 /* Use the actual color for the GUI and when 'termguicolors' is set. */
2580 } 2578 }
2581 else 2579 else
2582 #endif 2580 #endif
2583 if (id != 0 && t_colors >= 16) 2581 if (id != 0 && t_colors >= 16)
2584 { 2582 {
2585 int cterm_fg, cterm_bg; 2583 if (term_default_cterm_fg >= 0)
2586 2584 cterm_color2rgb(term_default_cterm_fg, fg);
2587 syn_id2cterm_bg(id, &cterm_fg, &cterm_bg); 2585 if (term_default_cterm_bg >= 0)
2588 if (cterm_fg >= 0) 2586 cterm_color2rgb(term_default_cterm_bg, bg);
2589 cterm_color2rgb(cterm_fg, fg);
2590 if (cterm_bg >= 0)
2591 cterm_color2rgb(cterm_bg, bg);
2592 } 2587 }
2593 else 2588 else
2594 { 2589 {
2595 #if defined(WIN3264) && !defined(FEAT_GUI_W32) 2590 #if defined(WIN3264) && !defined(FEAT_GUI_W32)
2596 int tmp; 2591 int tmp;
2700 tv.v_type = VAR_JOB; 2695 tv.v_type = VAR_JOB;
2701 tv.vval.v_job = term->tl_job; 2696 tv.vval.v_job = term->tl_job;
2702 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); 2697 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
2703 } 2698 }
2704 return abort; 2699 return abort;
2700 }
2701
2702 /*
2703 * Cache "Terminal" highlight group colors.
2704 */
2705 void
2706 set_terminal_default_colors(int cterm_fg, int cterm_bg)
2707 {
2708 term_default_cterm_fg = cterm_fg - 1;
2709 term_default_cterm_bg = cterm_bg - 1;
2705 } 2710 }
2706 2711
2707 /* 2712 /*
2708 * Get the buffer from the first argument in "argvars". 2713 * Get the buffer from the first argument in "argvars".
2709 * Returns NULL when the buffer is not for a terminal window. 2714 * Returns NULL when the buffer is not for a terminal window.