mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
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)
This commit is contained in:
@@ -213,9 +213,7 @@ void vterm_state_get_palette_color(const VTermState *state, int index, VTermColo
|
|||||||
void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg)
|
void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg)
|
||||||
{
|
{
|
||||||
state->default_fg = *default_fg;
|
state->default_fg = *default_fg;
|
||||||
state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
|
|
||||||
state->default_bg = *default_bg;
|
state->default_bg = *default_bg;
|
||||||
state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col)
|
void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col)
|
||||||
|
@@ -20,6 +20,7 @@ void term_change_in_curbuf(void);
|
|||||||
int term_get_attr(buf_T *buf, linenr_T lnum, int col);
|
int term_get_attr(buf_T *buf, linenr_T lnum, int col);
|
||||||
char_u *term_get_status_text(term_T *term);
|
char_u *term_get_status_text(term_T *term);
|
||||||
int set_ref_in_term(int copyID);
|
int set_ref_in_term(int copyID);
|
||||||
|
void set_terminal_default_colors(int cterm_fg, int cterm_bg);
|
||||||
void f_term_getaltscreen(typval_T *argvars, typval_T *rettv);
|
void f_term_getaltscreen(typval_T *argvars, typval_T *rettv);
|
||||||
void f_term_getattr(typval_T *argvars, typval_T *rettv);
|
void f_term_getattr(typval_T *argvars, typval_T *rettv);
|
||||||
void f_term_getcursor(typval_T *argvars, typval_T *rettv);
|
void f_term_getcursor(typval_T *argvars, typval_T *rettv);
|
||||||
|
12
src/syntax.c
12
src/syntax.c
@@ -7391,6 +7391,9 @@ do_highlight(
|
|||||||
int error = FALSE;
|
int error = FALSE;
|
||||||
int color;
|
int color;
|
||||||
int is_normal_group = FALSE; /* "Normal" group */
|
int is_normal_group = FALSE; /* "Normal" group */
|
||||||
|
#ifdef FEAT_TERMINAL
|
||||||
|
int is_terminal_group = FALSE; /* "Terminal" group */
|
||||||
|
#endif
|
||||||
#ifdef FEAT_GUI_X11
|
#ifdef FEAT_GUI_X11
|
||||||
int is_menu_group = FALSE; /* "Menu" group */
|
int is_menu_group = FALSE; /* "Menu" group */
|
||||||
int is_scrollbar_group = FALSE; /* "Scrollbar" group */
|
int is_scrollbar_group = FALSE; /* "Scrollbar" group */
|
||||||
@@ -7616,6 +7619,10 @@ do_highlight(
|
|||||||
|
|
||||||
if (STRCMP(HL_TABLE()[idx].sg_name_u, "NORMAL") == 0)
|
if (STRCMP(HL_TABLE()[idx].sg_name_u, "NORMAL") == 0)
|
||||||
is_normal_group = TRUE;
|
is_normal_group = TRUE;
|
||||||
|
#ifdef FEAT_TERMINAL
|
||||||
|
else if (STRCMP(HL_TABLE()[idx].sg_name_u, "TERMINAL") == 0)
|
||||||
|
is_terminal_group = TRUE;
|
||||||
|
#endif
|
||||||
#ifdef FEAT_GUI_X11
|
#ifdef FEAT_GUI_X11
|
||||||
else if (STRCMP(HL_TABLE()[idx].sg_name_u, "MENU") == 0)
|
else if (STRCMP(HL_TABLE()[idx].sg_name_u, "MENU") == 0)
|
||||||
is_menu_group = TRUE;
|
is_menu_group = TRUE;
|
||||||
@@ -8239,6 +8246,11 @@ do_highlight(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#ifdef FEAT_TERMINAL
|
||||||
|
else if (is_terminal_group)
|
||||||
|
set_terminal_default_colors(
|
||||||
|
HL_TABLE()[idx].sg_cterm_fg, HL_TABLE()[idx].sg_cterm_bg);
|
||||||
|
#endif
|
||||||
#ifdef FEAT_GUI_X11
|
#ifdef FEAT_GUI_X11
|
||||||
# ifdef FEAT_MENU
|
# ifdef FEAT_MENU
|
||||||
else if (is_menu_group)
|
else if (is_menu_group)
|
||||||
|
@@ -188,6 +188,9 @@ static void term_free_vterm(term_T *term);
|
|||||||
* backspace key. */
|
* backspace key. */
|
||||||
static int term_backspace_char = BS;
|
static int term_backspace_char = BS;
|
||||||
|
|
||||||
|
/* "Terminal" highlight group colors. */
|
||||||
|
static int term_default_cterm_fg = -1;
|
||||||
|
static int term_default_cterm_bg = -1;
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
* 1. Generic code for all systems.
|
* 1. Generic code for all systems.
|
||||||
@@ -1834,20 +1837,12 @@ cell2attr(VTermScreenCellAttrs cellattrs, VTermColor cellfg, VTermColor cellbg)
|
|||||||
int bg = color2index(&cellbg, FALSE, &bold);
|
int bg = color2index(&cellbg, FALSE, &bold);
|
||||||
|
|
||||||
/* Use the "Terminal" highlighting for the default colors. */
|
/* Use the "Terminal" highlighting for the default colors. */
|
||||||
if (fg == 0 || bg == 0)
|
if ((fg == 0 || bg == 0) && t_colors >= 16)
|
||||||
{
|
{
|
||||||
int id = syn_name2id((char_u *)"Terminal");
|
if (fg == 0 && term_default_cterm_fg >= 0)
|
||||||
|
fg = term_default_cterm_fg + 1;
|
||||||
if (id != 0 && t_colors >= 16)
|
if (bg == 0 && term_default_cterm_bg >= 0)
|
||||||
{
|
bg = term_default_cterm_bg + 1;
|
||||||
int cterm_fg, cterm_bg;
|
|
||||||
|
|
||||||
syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
|
|
||||||
if (cterm_fg >= 0)
|
|
||||||
fg = cterm_fg + 1;
|
|
||||||
if (cterm_bg >= 0)
|
|
||||||
bg = cterm_bg + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* with 8 colors set the bold attribute to get a bright foreground */
|
/* with 8 colors set the bold attribute to get a bright foreground */
|
||||||
@@ -2470,6 +2465,7 @@ cterm_color2rgb(int nr, VTermColor *rgb)
|
|||||||
rgb->blue = cube_value[idx % 6];
|
rgb->blue = cube_value[idx % 6];
|
||||||
rgb->green = cube_value[idx / 6 % 6];
|
rgb->green = cube_value[idx / 6 % 6];
|
||||||
rgb->red = cube_value[idx / 36 % 6];
|
rgb->red = cube_value[idx / 36 % 6];
|
||||||
|
rgb->ansi_index = VTERM_ANSI_INDEX_NONE;
|
||||||
}
|
}
|
||||||
else if (nr < 256)
|
else if (nr < 256)
|
||||||
{
|
{
|
||||||
@@ -2478,6 +2474,7 @@ cterm_color2rgb(int nr, VTermColor *rgb)
|
|||||||
rgb->blue = grey_ramp[idx];
|
rgb->blue = grey_ramp[idx];
|
||||||
rgb->green = grey_ramp[idx];
|
rgb->green = grey_ramp[idx];
|
||||||
rgb->red = grey_ramp[idx];
|
rgb->red = grey_ramp[idx];
|
||||||
|
rgb->ansi_index = VTERM_ANSI_INDEX_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2520,6 +2517,7 @@ create_vterm(term_T *term, int rows, int cols)
|
|||||||
}
|
}
|
||||||
fg->red = fg->green = fg->blue = fgval;
|
fg->red = fg->green = fg->blue = fgval;
|
||||||
bg->red = bg->green = bg->blue = bgval;
|
bg->red = bg->green = bg->blue = bgval;
|
||||||
|
fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT;
|
||||||
|
|
||||||
/* The "Terminal" highlight group overrules the defaults. */
|
/* The "Terminal" highlight group overrules the defaults. */
|
||||||
id = syn_name2id((char_u *)"Terminal");
|
id = syn_name2id((char_u *)"Terminal");
|
||||||
@@ -2582,13 +2580,10 @@ create_vterm(term_T *term, int rows, int cols)
|
|||||||
#endif
|
#endif
|
||||||
if (id != 0 && t_colors >= 16)
|
if (id != 0 && t_colors >= 16)
|
||||||
{
|
{
|
||||||
int cterm_fg, cterm_bg;
|
if (term_default_cterm_fg >= 0)
|
||||||
|
cterm_color2rgb(term_default_cterm_fg, fg);
|
||||||
syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
|
if (term_default_cterm_bg >= 0)
|
||||||
if (cterm_fg >= 0)
|
cterm_color2rgb(term_default_cterm_bg, bg);
|
||||||
cterm_color2rgb(cterm_fg, fg);
|
|
||||||
if (cterm_bg >= 0)
|
|
||||||
cterm_color2rgb(cterm_bg, bg);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2704,6 +2699,16 @@ set_ref_in_term(int copyID)
|
|||||||
return abort;
|
return abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cache "Terminal" highlight group colors.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
set_terminal_default_colors(int cterm_fg, int cterm_bg)
|
||||||
|
{
|
||||||
|
term_default_cterm_fg = cterm_fg - 1;
|
||||||
|
term_default_cterm_bg = cterm_bg - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the buffer from the first argument in "argvars".
|
* Get the buffer from the first argument in "argvars".
|
||||||
* Returns NULL when the buffer is not for a terminal window.
|
* Returns NULL when the buffer is not for a terminal window.
|
||||||
|
@@ -771,6 +771,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1362,
|
||||||
/**/
|
/**/
|
||||||
1361,
|
1361,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user