Skip to content

Commit a7c54cf

Browse files
committed
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)
1 parent 97ce419 commit a7c54cf

5 files changed

Lines changed: 40 additions & 22 deletions

File tree

src/libvterm/src/pen.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ void vterm_state_get_palette_color(const VTermState *state, int index, VTermColo
213213
void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg)
214214
{
215215
state->default_fg = *default_fg;
216-
state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
217216
state->default_bg = *default_bg;
218-
state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
219217
}
220218

221219
void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col)

src/proto/terminal.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void term_change_in_curbuf(void);
2020
int term_get_attr(buf_T *buf, linenr_T lnum, int col);
2121
char_u *term_get_status_text(term_T *term);
2222
int set_ref_in_term(int copyID);
23+
void set_terminal_default_colors(int cterm_fg, int cterm_bg);
2324
void f_term_getaltscreen(typval_T *argvars, typval_T *rettv);
2425
void f_term_getattr(typval_T *argvars, typval_T *rettv);
2526
void f_term_getcursor(typval_T *argvars, typval_T *rettv);

src/syntax.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7391,6 +7391,9 @@ do_highlight(
73917391
int error = FALSE;
73927392
int color;
73937393
int is_normal_group = FALSE; /* "Normal" group */
7394+
#ifdef FEAT_TERMINAL
7395+
int is_terminal_group = FALSE; /* "Terminal" group */
7396+
#endif
73947397
#ifdef FEAT_GUI_X11
73957398
int is_menu_group = FALSE; /* "Menu" group */
73967399
int is_scrollbar_group = FALSE; /* "Scrollbar" group */
@@ -7616,6 +7619,10 @@ do_highlight(
76167619

76177620
if (STRCMP(HL_TABLE()[idx].sg_name_u, "NORMAL") == 0)
76187621
is_normal_group = TRUE;
7622+
#ifdef FEAT_TERMINAL
7623+
else if (STRCMP(HL_TABLE()[idx].sg_name_u, "TERMINAL") == 0)
7624+
is_terminal_group = TRUE;
7625+
#endif
76197626
#ifdef FEAT_GUI_X11
76207627
else if (STRCMP(HL_TABLE()[idx].sg_name_u, "MENU") == 0)
76217628
is_menu_group = TRUE;
@@ -8239,6 +8246,11 @@ do_highlight(
82398246
}
82408247
#endif
82418248
}
8249+
#ifdef FEAT_TERMINAL
8250+
else if (is_terminal_group)
8251+
set_terminal_default_colors(
8252+
HL_TABLE()[idx].sg_cterm_fg, HL_TABLE()[idx].sg_cterm_bg);
8253+
#endif
82428254
#ifdef FEAT_GUI_X11
82438255
# ifdef FEAT_MENU
82448256
else if (is_menu_group)

src/terminal.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ static void term_free_vterm(term_T *term);
188188
* backspace key. */
189189
static 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.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1362,
774776
/**/
775777
1361,
776778
/**/

0 commit comments

Comments
 (0)