@@ -188,6 +188,9 @@ static void term_free_vterm(term_T *term);
188188 * backspace key. */
189189static int term_backspace_char = BS ;
190190
191+ /* "Terminal" highlight group colors. */
192+ static int term_default_cterm_fg = -1 ;
193+ static int term_default_cterm_bg = -1 ;
191194
192195/**************************************
193196 * 1. Generic code for all systems.
@@ -1834,20 +1837,12 @@ cell2attr(VTermScreenCellAttrs cellattrs, VTermColor cellfg, VTermColor cellbg)
18341837 int bg = color2index (& cellbg , FALSE, & bold );
18351838
18361839 /* Use the "Terminal" highlighting for the default colors. */
1837- if (fg == 0 || bg == 0 )
1840+ if (( fg == 0 || bg == 0 ) && t_colors >= 16 )
18381841 {
1839- int id = syn_name2id ((char_u * )"Terminal" );
1840-
1841- if (id != 0 && t_colors >= 16 )
1842- {
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- }
1842+ if (fg == 0 && term_default_cterm_fg >= 0 )
1843+ fg = term_default_cterm_fg + 1 ;
1844+ if (bg == 0 && term_default_cterm_bg >= 0 )
1845+ bg = term_default_cterm_bg + 1 ;
18511846 }
18521847
18531848 /* with 8 colors set the bold attribute to get a bright foreground */
@@ -2470,6 +2465,7 @@ cterm_color2rgb(int nr, VTermColor *rgb)
24702465 rgb -> blue = cube_value [idx % 6 ];
24712466 rgb -> green = cube_value [idx / 6 % 6 ];
24722467 rgb -> red = cube_value [idx / 36 % 6 ];
2468+ rgb -> ansi_index = VTERM_ANSI_INDEX_NONE ;
24732469 }
24742470 else if (nr < 256 )
24752471 {
@@ -2478,6 +2474,7 @@ cterm_color2rgb(int nr, VTermColor *rgb)
24782474 rgb -> blue = grey_ramp [idx ];
24792475 rgb -> green = grey_ramp [idx ];
24802476 rgb -> red = grey_ramp [idx ];
2477+ rgb -> ansi_index = VTERM_ANSI_INDEX_NONE ;
24812478 }
24822479}
24832480
@@ -2520,6 +2517,7 @@ create_vterm(term_T *term, int rows, int cols)
25202517 }
25212518 fg -> red = fg -> green = fg -> blue = fgval ;
25222519 bg -> red = bg -> green = bg -> blue = bgval ;
2520+ fg -> ansi_index = bg -> ansi_index = VTERM_ANSI_INDEX_DEFAULT ;
25232521
25242522 /* The "Terminal" highlight group overrules the defaults. */
25252523 id = syn_name2id ((char_u * )"Terminal" );
@@ -2582,13 +2580,10 @@ create_vterm(term_T *term, int rows, int cols)
25822580#endif
25832581 if (id != 0 && t_colors >= 16 )
25842582 {
2585- int cterm_fg , cterm_bg ;
2586-
2587- syn_id2cterm_bg (id , & cterm_fg , & cterm_bg );
2588- if (cterm_fg >= 0 )
2589- cterm_color2rgb (cterm_fg , fg );
2590- if (cterm_bg >= 0 )
2591- cterm_color2rgb (cterm_bg , bg );
2583+ if (term_default_cterm_fg >= 0 )
2584+ cterm_color2rgb (term_default_cterm_fg , fg );
2585+ if (term_default_cterm_bg >= 0 )
2586+ cterm_color2rgb (term_default_cterm_bg , bg );
25922587 }
25932588 else
25942589 {
@@ -2704,6 +2699,16 @@ set_ref_in_term(int copyID)
27042699 return abort ;
27052700}
27062701
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 ;
2710+ }
2711+
27072712/*
27082713 * Get the buffer from the first argument in "argvars".
27092714 * Returns NULL when the buffer is not for a terminal window.
0 commit comments