changeset 26193:c83460a14407 v8.2.3628

patch 8.2.3628: looking terminal colors is a bit slow Commit: https://github.com/vim/vim/commit/87fd0924e2d85213cc111ee7a5122f92216a37c7 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 20 13:47:45 2021 +0000 patch 8.2.3628: looking terminal colors is a bit slow Problem: Looking terminal colors is a bit slow. Solution: Cache the terminal colors. (closes https://github.com/vim/vim/issues/9130, closes https://github.com/vim/vim/issues/9058)
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Nov 2021 15:00:05 +0100
parents e3ce27989e21
children 9dab308df27e
files src/highlight.c src/libvterm/include/vterm.h src/option.c src/optionstr.c src/popupwin.c src/proto/terminal.pro src/structs.h src/terminal.c src/testdir/dumps/Test_terminal_color_MyTermCol.dump src/testdir/dumps/Test_terminal_color_MyTermCol_over_Terminal.dump src/testdir/dumps/Test_terminal_color_MyWinCol.dump src/testdir/dumps/Test_terminal_color_MyWinCol_over_group.dump src/testdir/dumps/Test_terminal_color_Terminal.dump src/testdir/dumps/Test_terminal_color_gui_MyTermCol.dump src/testdir/dumps/Test_terminal_color_gui_MyWinCol.dump src/testdir/dumps/Test_terminal_color_gui_Terminal.dump src/testdir/dumps/Test_terminal_color_gui_transp_MyTermCol.dump src/testdir/dumps/Test_terminal_color_gui_transp_MyWinCol.dump src/testdir/dumps/Test_terminal_color_gui_transp_Terminal.dump src/testdir/dumps/Test_terminal_color_transp_MyTermCol.dump src/testdir/dumps/Test_terminal_color_transp_MyWinCol.dump src/testdir/dumps/Test_terminal_color_transp_Terminal.dump src/testdir/dumps/Test_terminal_popup_MyPopupHlCol.dump src/testdir/dumps/Test_terminal_popup_MyTermCol_over_Terminal.dump src/testdir/dumps/Test_terminal_popup_MyWinCol.dump src/testdir/dumps/Test_terminal_popup_MyWinCol_over_group.dump src/testdir/dumps/Test_terminal_popup_gui_MyPopupHlCol.dump src/testdir/dumps/Test_terminal_popup_gui_MyTermCol.dump src/testdir/dumps/Test_terminal_popup_gui_MyWinCol.dump src/testdir/dumps/Test_terminal_popup_gui_Terminal.dump src/testdir/dumps/Test_terminal_popup_gui_transp_MyPopupHlCol.dump src/testdir/dumps/Test_terminal_popup_gui_transp_MyTermCol.dump src/testdir/dumps/Test_terminal_popup_gui_transp_MyWinCol.dump src/testdir/dumps/Test_terminal_popup_gui_transp_Terminal.dump src/testdir/dumps/Test_terminal_popup_transp_MyPopupHlCol.dump src/testdir/dumps/Test_terminal_popup_transp_MyTermCol.dump src/testdir/dumps/Test_terminal_popup_transp_MyWinCol.dump src/testdir/dumps/Test_terminal_popup_transp_Terminal.dump src/testdir/dumps/Test_terminal_wincolor_split_MyWinCol.dump src/testdir/dumps/Test_terminal_wincolor_split_MyWinCol2.dump src/testdir/test_terminal3.vim src/version.c src/window.c
diffstat 43 files changed, 1059 insertions(+), 215 deletions(-) [+]
line wrap: on
line diff
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -3753,6 +3753,11 @@ highlight_changed(void)
 
     need_highlight_changed = FALSE;
 
+#ifdef FEAT_TERMINAL
+    term_update_colors_all();
+    term_update_wincolor_all();
+#endif
+
     // Clear all attributes.
     for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf)
 	highlight_attr[hlf] = 0;
--- a/src/libvterm/include/vterm.h
+++ b/src/libvterm/include/vterm.h
@@ -122,7 +122,12 @@ typedef enum {
   /**
    * Mask that can be used to extract the default foreground/background bit.
    */
-  VTERM_COLOR_DEFAULT_MASK = 0x06
+  VTERM_COLOR_DEFAULT_MASK = 0x06,
+
+  /**
+   * If set, indicates that the color is invalid.
+   */
+  VTERM_COLOR_INVALID = 0x08
 } VTermColorType;
 
 /**
@@ -155,6 +160,12 @@ typedef enum {
 #define VTERM_COLOR_IS_DEFAULT_BG(col) \
   (!!((col)->type & VTERM_COLOR_DEFAULT_BG))
 
+/**
+ * Returns true if the VTERM_COLOR_INVALID `type` flag is set, indicating
+ * that the given VTermColor instance is an invalid color.
+ */
+#define VTERM_COLOR_IS_INVALID(col) (!!((col)->type & VTERM_COLOR_INVALID))
+
 typedef struct {
   /**
    * Tag indicating which member is actually valid.
--- a/src/option.c
+++ b/src/option.c
@@ -3259,6 +3259,10 @@ set_bool_option(
 	    init_highlight(TRUE, FALSE);
 	}
 # endif
+# ifdef FEAT_TERMINAL
+	term_update_colors_all();
+	term_update_wincolor_all();
+# endif
     }
 #endif
 
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -2205,10 +2205,7 @@ ambw_end:
     }
     // 'wincolor'
     else if (varp == &curwin->w_p_wcr)
-    {
-	if (curwin->w_buffer->b_term != NULL)
-	    term_update_colors(curwin->w_buffer->b_term);
-    }
+	term_update_wincolor(curwin);
 # if defined(MSWIN)
     // 'termwintype'
     else if (varp == &p_twt)
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -732,8 +732,13 @@ apply_general_options(win_T *wp, dict_T 
 
     str = dict_get_string(dict, (char_u *)"highlight", FALSE);
     if (str != NULL)
+    {
 	set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
 						   str, OPT_FREE|OPT_LOCAL, 0);
+#ifdef FEAT_TERMINAL
+	term_update_wincolor(wp);
+#endif
+    }
 
     set_padding_border(dict, wp->w_popup_padding, "padding", 999);
     set_padding_border(dict, wp->w_popup_border, "border", 1);
--- a/src/proto/terminal.pro
+++ b/src/proto/terminal.pro
@@ -28,7 +28,9 @@ int term_is_finished(buf_T *buf);
 int term_show_buffer(buf_T *buf);
 void term_change_in_curbuf(void);
 int term_get_attr(win_T *wp, linenr_T lnum, int col);
-void term_update_colors(term_T *term);
+void term_reset_wincolor(win_T *wp);
+void term_update_wincolor(win_T *wp);
+void term_update_wincolor_all(void);
 void term_update_colors_all(void);
 char_u *term_get_status_text(term_T *term);
 void term_clear_status_text(term_T *term);
--- a/src/structs.h
+++ b/src/structs.h
@@ -123,6 +123,14 @@ typedef struct {
 #endif
 #define COLOR_INVALID(x) ((x) == INVALCOLOR || (x) == CTERMCOLOR)
 
+#ifdef FEAT_TERMINAL
+# include "libvterm/include/vterm.h"
+typedef struct {
+    VTermColor	fg;
+    VTermColor	bg;
+} termcellcolor_T;
+#endif
+
 /*
  * marks: positions in a file
  * (a normal mark is a lnum/col pair, the same as a file position)
@@ -3619,6 +3627,9 @@ struct window_S
     int		w_nrwidth;	    // width of 'number' and 'relativenumber'
 				    // column being used
 #endif
+#ifdef FEAT_TERMINAL
+    termcellcolor_T w_term_wincolor;	 // cache for term color of 'wincolor'
+#endif
 
     /*
      * === end of cached values ===
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -2319,14 +2319,21 @@ terminal_is_active()
 }
 
 /*
- * Return the highight group name for the terminal; "Terminal" if not set.
+ * Return the highight group ID for the terminal and the window.
  */
-    static char_u *
-term_get_highlight_name(term_T *term)
-{
-    if (term->tl_highlight_name == NULL)
-	return (char_u *)"Terminal";
-    return term->tl_highlight_name;
+    static int
+term_get_highlight_id(term_T *term, win_T *wp)
+{
+    char_u *name;
+
+    if (wp != NULL && *wp->w_p_wcr != NUL)
+	name = wp->w_p_wcr;
+    else if (term->tl_highlight_name != NULL)
+	name = term->tl_highlight_name;
+    else
+	name = (char_u*)"Terminal";
+
+    return syn_name2id(name);
 }
 
 #if defined(FEAT_GUI) || defined(PROTO)
@@ -2336,7 +2343,8 @@ term_get_cursor_shape(guicolor_T *fg, gu
     term_T		 *term = in_terminal_loop;
     static cursorentry_T entry;
     int			 id;
-    guicolor_T		term_fg, term_bg;
+    guicolor_T		 term_fg = INVALCOLOR;
+    guicolor_T		 term_bg = INVALCOLOR;
 
     CLEAR_FIELD(entry);
     entry.shape = entry.mshape =
@@ -2352,18 +2360,17 @@ term_get_cursor_shape(guicolor_T *fg, gu
     }
 
     // The highlight group overrules the defaults.
-    id = syn_name2id(term_get_highlight_name(term));
+    id = term_get_highlight_id(term, curwin);
     if (id != 0)
-    {
 	syn_id2colors(id, &term_fg, &term_bg);
+    if (term_bg != INVALCOLOR)
 	*fg = term_bg;
-    }
     else
 	*fg = gui.back_pixel;
 
     if (term->tl_cursor_color == NULL)
     {
-	if (id != 0)
+	if (term_fg != INVALCOLOR)
 	    *bg = term_fg;
 	else
 	    *bg = gui.norm_pixel;
@@ -2743,8 +2750,7 @@ color2index(VTermColor *color, int fg, i
     int blue = color->blue;
     int green = color->green;
 
-    if (VTERM_COLOR_IS_DEFAULT_FG(color)
-	    || VTERM_COLOR_IS_DEFAULT_BG(color))
+    if (VTERM_COLOR_IS_INVALID(color))
 	return 0;
     if (VTERM_COLOR_IS_INDEXED(color))
     {
@@ -2815,19 +2821,19 @@ color2index(VTermColor *color, int fg, i
  * Convert Vterm attributes to highlight flags.
  */
     static int
-vtermAttr2hl(VTermScreenCellAttrs cellattrs)
+vtermAttr2hl(VTermScreenCellAttrs *cellattrs)
 {
     int attr = 0;
 
-    if (cellattrs.bold)
+    if (cellattrs->bold)
 	attr |= HL_BOLD;
-    if (cellattrs.underline)
+    if (cellattrs->underline)
 	attr |= HL_UNDERLINE;
-    if (cellattrs.italic)
+    if (cellattrs->italic)
 	attr |= HL_ITALIC;
-    if (cellattrs.strike)
+    if (cellattrs->strike)
 	attr |= HL_STRIKETHROUGH;
-    if (cellattrs.reverse)
+    if (cellattrs->reverse)
 	attr |= HL_INVERSE;
     return attr;
 }
@@ -2858,88 +2864,66 @@ hl2vtermAttr(int attr, cellattr_T *cell)
 cell2attr(
 	term_T			*term,
 	win_T			*wp,
-	VTermScreenCellAttrs	cellattrs,
-	VTermColor		cellfg,
-	VTermColor		cellbg)
+	VTermScreenCellAttrs	*cellattrs,
+	VTermColor		*cellfg,
+	VTermColor		*cellbg)
 {
     int attr = vtermAttr2hl(cellattrs);
+    VTermColor *fg = cellfg;
+    VTermColor *bg = cellbg;
+    int is_default_fg = VTERM_COLOR_IS_DEFAULT_FG(fg);
+    int is_default_bg = VTERM_COLOR_IS_DEFAULT_BG(bg);
+
+    if (is_default_fg || is_default_bg)
+    {
+	if (wp != NULL && *wp->w_p_wcr != NUL)
+	{
+	    if (is_default_fg)
+		fg = &wp->w_term_wincolor.fg;
+	    if (is_default_bg)
+		bg = &wp->w_term_wincolor.bg;
+	}
+	else
+	{
+	    if (is_default_fg)
+		fg = &term->tl_default_color.fg;
+	    if (is_default_bg)
+		bg = &term->tl_default_color.bg;
+	}
+    }
 
 #ifdef FEAT_GUI
     if (gui.in_use)
     {
-	guicolor_T fg, bg;
-
-	fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue);
-	bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue);
-	return get_gui_attr_idx(attr, fg, bg);
+	guicolor_T guifg = gui_mch_get_rgb_color(fg->red, fg->green, fg->blue);
+	guicolor_T guibg = gui_mch_get_rgb_color(bg->red, bg->green, bg->blue);
+	return get_gui_attr_idx(attr, guifg, guibg);
     }
     else
 #endif
 #ifdef FEAT_TERMGUICOLORS
     if (p_tgc)
     {
-	guicolor_T fg = INVALCOLOR;
-	guicolor_T bg = INVALCOLOR;
-
-	// Use the 'wincolor' or "Terminal" highlighting for the default
-	// colors.
-	if (VTERM_COLOR_IS_DEFAULT_FG(&cellfg)
-		|| VTERM_COLOR_IS_DEFAULT_BG(&cellbg))
-	{
-	    int id = 0;
-
-	    if (wp != NULL && *wp->w_p_wcr != NUL)
-		id = syn_name2id(wp->w_p_wcr);
-	    if (id == 0)
-		id = syn_name2id(term_get_highlight_name(term));
-	    if (id > 0)
-		syn_id2colors(id, &fg, &bg);
-	    if (!VTERM_COLOR_IS_DEFAULT_FG(&cellfg))
-		fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green,
-					   cellfg.blue);
-	    if (!VTERM_COLOR_IS_DEFAULT_BG(&cellbg))
-		bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green,
-					   cellbg.blue);
-	}
-	else
-	{
-	    fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue);
-	    bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue);
-	}
-
-	return get_tgc_attr_idx(attr, fg, bg);
+	guicolor_T tgcfg = VTERM_COLOR_IS_INVALID(fg)
+	    ? INVALCOLOR
+	    : gui_get_rgb_color_cmn(fg->red, fg->green, fg->blue);
+	guicolor_T tgcbg = VTERM_COLOR_IS_INVALID(bg)
+	    ? INVALCOLOR
+	    : gui_get_rgb_color_cmn(bg->red, bg->green, bg->blue);
+	return get_tgc_attr_idx(attr, tgcfg, tgcbg);
     }
     else
 #endif
     {
 	int bold = MAYBE;
-	int fg = color2index(&cellfg, TRUE, &bold);
-	int bg = color2index(&cellbg, FALSE, &bold);
-
-	// Use the 'wincolor' or "Terminal" highlighting for the default
-	// colors.
-	if ((fg == 0 || bg == 0) && t_colors >= 16)
-	{
-	    int cterm_fg = -1;
-	    int cterm_bg = -1;
-	    int id = 0;
-
-	    if (wp != NULL && *wp->w_p_wcr != NUL)
-		id = syn_name2id(wp->w_p_wcr);
-	    if (id == 0)
-		id = syn_name2id(term_get_highlight_name(term));
-	    if (id > 0)
-		syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
-	    if (fg == 0 && cterm_fg >= 0)
-		fg = cterm_fg + 1;
-	    if (bg == 0 && cterm_bg >= 0)
-		bg = cterm_bg + 1;
-	}
+	int ctermfg = color2index(fg, TRUE, &bold);
+	int ctermbg = color2index(bg, FALSE, &bold);
 
 	// with 8 colors set the bold attribute to get a bright foreground
 	if (bold == TRUE)
 	    attr |= HL_BOLD;
-	return get_cterm_attr_idx(attr, fg, bg);
+
+	return get_cterm_attr_idx(attr, ctermfg, ctermbg);
     }
     return 0;
 }
@@ -2988,7 +2972,7 @@ term_scroll_up(term_T *term, int start_r
 	    // Set the color to clear lines with.
 	    vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
 								     &fg, &bg);
-	    clear_attr = cell2attr(term, wp, attr, fg, bg);
+	    clear_attr = cell2attr(term, wp, &attr, &fg, &bg);
 	    win_del_lines(wp, start_row, count, FALSE, FALSE, clear_attr);
 	}
     }
@@ -3633,7 +3617,8 @@ term_line2screenline(
 		// This will only store the lower byte of "c".
 		ScreenLines[off] = c;
 	}
-	ScreenAttrs[off] = cell2attr(term, wp, cell.attrs, cell.fg, cell.bg);
+	ScreenAttrs[off] = cell2attr(term, wp, &cell.attrs, &cell.fg,
+								     &cell.bg);
 
 	++pos->col;
 	++off;
@@ -3893,7 +3878,7 @@ term_get_attr(win_T *wp, linenr_T lnum, 
 	else
 	    cellattr = line->sb_cells + col;
     }
-    return cell2attr(term, wp, cellattr->attrs, cellattr->fg, cellattr->bg);
+    return cell2attr(term, wp, &cellattr->attrs, &cellattr->fg, &cellattr->bg);
 }
 
 /*
@@ -3914,10 +3899,131 @@ cterm_color2vterm(int nr, VTermColor *rg
 }
 
 /*
+ * Initialize vterm color from the synID.
+ * Returns TRUE if color is set to "fg" and "bg".
+ * Otherwise returns FALSE.
+ */
+    static int
+get_vterm_color_from_synid(int id, VTermColor *fg, VTermColor *bg)
+{
+#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
+    // Use the actual color for the GUI and when 'termguicolors' is set.
+    if (0
+# ifdef FEAT_GUI
+	    || gui.in_use
+# endif
+# ifdef FEAT_TERMGUICOLORS
+	    || p_tgc
+#  ifdef FEAT_VTP
+	    // Finally get INVALCOLOR on this execution path
+	    || (!p_tgc && t_colors >= 256)
+#  endif
+# endif
+       )
+    {
+	guicolor_T fg_rgb = INVALCOLOR;
+	guicolor_T bg_rgb = INVALCOLOR;
+
+	if (id > 0)
+	    syn_id2colors(id, &fg_rgb, &bg_rgb);
+
+	if (fg_rgb != INVALCOLOR)
+	{
+	    long_u rgb = GUI_MCH_GET_RGB(fg_rgb);
+	    fg->red = (unsigned)(rgb >> 16);
+	    fg->green = (unsigned)(rgb >> 8) & 255;
+	    fg->blue = (unsigned)rgb & 255;
+	    fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG;
+	}
+	else
+	    fg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
+
+	if (bg_rgb != INVALCOLOR)
+	{
+	    long_u rgb = GUI_MCH_GET_RGB(bg_rgb);
+	    bg->red = (unsigned)(rgb >> 16);
+	    bg->green = (unsigned)(rgb >> 8) & 255;
+	    bg->blue = (unsigned)rgb & 255;
+	    bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG;
+	}
+	else
+	    bg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
+
+	return TRUE;
+    }
+    else
+#endif
+    if (t_colors >= 16)
+    {
+	int cterm_fg = -1;
+	int cterm_bg = -1;
+
+	if (id > 0)
+	    syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
+
+	if (cterm_fg >= 0)
+	{
+	    cterm_color2vterm(cterm_fg, fg);
+	    fg->type |= VTERM_COLOR_DEFAULT_FG;
+	}
+	else
+	    fg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
+
+	if (cterm_bg >= 0)
+	{
+	    cterm_color2vterm(cterm_bg, bg);
+	    bg->type |= VTERM_COLOR_DEFAULT_BG;
+	}
+	else
+	    bg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
+
+	return TRUE;
+    }
+
+    return FALSE;
+}
+
+    void
+term_reset_wincolor(win_T *wp)
+{
+    wp->w_term_wincolor.fg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
+    wp->w_term_wincolor.bg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
+}
+
+/*
+ * Cache the color of 'wincolor'.
+ */
+    void
+term_update_wincolor(win_T *wp)
+{
+    int id = 0;
+
+    if (*wp->w_p_wcr != NUL)
+	id = syn_name2id(wp->w_p_wcr);
+    if (id == 0 || !get_vterm_color_from_synid(id, &wp->w_term_wincolor.fg,
+						      &wp->w_term_wincolor.bg))
+	term_reset_wincolor(wp);
+}
+
+/*
+ * Called when option 'termguicolors' was set,
+ * or when any highlight is changed.
+ */
+    void
+term_update_wincolor_all()
+{
+    win_T	 *wp = NULL;
+    int		 did_curwin = FALSE;
+
+    while (for_all_windows_and_curwin(&wp, &did_curwin))
+	term_update_wincolor(wp);
+}
+
+/*
  * Initialize term->tl_default_color from the environment.
  */
     static void
-init_default_colors(term_T *term, win_T *wp)
+init_default_colors(term_T *term)
 {
     VTermColor	    *fg, *bg;
     int		    fgval, bgval;
@@ -3945,84 +4051,10 @@ init_default_colors(term_T *term, win_T 
     fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG;
     bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG;
 
-    // The 'wincolor' or the highlight group overrules the defaults.
-    if (wp != NULL && *wp->w_p_wcr != NUL)
-	id = syn_name2id(wp->w_p_wcr);
-    else
-	id = syn_name2id(term_get_highlight_name(term));
-
-    // Use the actual color for the GUI and when 'termguicolors' is set.
-#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
-    if (0
-# ifdef FEAT_GUI
-	    || gui.in_use
-# endif
-# ifdef FEAT_TERMGUICOLORS
-	    || p_tgc
-#  ifdef FEAT_VTP
-	    // Finally get INVALCOLOR on this execution path
-	    || (!p_tgc && t_colors >= 256)
-#  endif
-# endif
-       )
-    {
-	guicolor_T	fg_rgb = INVALCOLOR;
-	guicolor_T	bg_rgb = INVALCOLOR;
-
-	if (id != 0)
-	    syn_id2colors(id, &fg_rgb, &bg_rgb);
-
-# ifdef FEAT_GUI
-	if (gui.in_use)
-	{
-	    if (fg_rgb == INVALCOLOR)
-		fg_rgb = gui.norm_pixel;
-	    if (bg_rgb == INVALCOLOR)
-		bg_rgb = gui.back_pixel;
-	}
-#  ifdef FEAT_TERMGUICOLORS
-	else
-#  endif
-# endif
-# ifdef FEAT_TERMGUICOLORS
-	{
-	    if (fg_rgb == INVALCOLOR)
-		fg_rgb = cterm_normal_fg_gui_color;
-	    if (bg_rgb == INVALCOLOR)
-		bg_rgb = cterm_normal_bg_gui_color;
-	}
-# endif
-	if (fg_rgb != INVALCOLOR)
-	{
-	    long_u rgb = GUI_MCH_GET_RGB(fg_rgb);
-
-	    fg->red = (unsigned)(rgb >> 16);
-	    fg->green = (unsigned)(rgb >> 8) & 255;
-	    fg->blue = (unsigned)rgb & 255;
-	}
-	if (bg_rgb != INVALCOLOR)
-	{
-	    long_u rgb = GUI_MCH_GET_RGB(bg_rgb);
-
-	    bg->red = (unsigned)(rgb >> 16);
-	    bg->green = (unsigned)(rgb >> 8) & 255;
-	    bg->blue = (unsigned)rgb & 255;
-	}
-    }
-    else
-#endif
-    if (id != 0 && t_colors >= 16)
-    {
-	int cterm_fg = -1;
-	int cterm_bg = -1;
-	syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
-
-	if (cterm_fg >= 0)
-	    cterm_color2vterm(cterm_fg, fg);
-	if (cterm_bg >= 0)
-	    cterm_color2vterm(cterm_bg, bg);
-    }
-    else
+    // The highlight group overrules the defaults.
+    id = term_get_highlight_id(term, NULL);
+
+    if (!get_vterm_color_from_synid(id, fg, bg))
     {
 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
 	int tmp;
@@ -4532,7 +4564,7 @@ create_vterm(term_T *term, int rows, int
     // TODO: depends on 'encoding'.
     vterm_set_utf8(vterm, 1);
 
-    init_default_colors(term, NULL);
+    init_default_colors(term);
 
     vterm_state_set_default_colors(
 	    state,
@@ -4568,36 +4600,24 @@ create_vterm(term_T *term, int rows, int
 }
 
 /*
- * Called when 'wincolor' was set.
- */
-    void
-term_update_colors(term_T *term)
-{
-    win_T *wp;
-
-    if (term->tl_vterm == NULL)
-	return;
-    init_default_colors(term, curwin);
-    vterm_state_set_default_colors(
-	    vterm_obtain_state(term->tl_vterm),
-	    &term->tl_default_color.fg,
-	    &term->tl_default_color.bg);
-
-    FOR_ALL_WINDOWS(wp)
-	if (wp->w_buffer == term->tl_buffer)
-	    redraw_win_later(wp, NOT_VALID);
-}
-
-/*
- * Called when 'background' was set.
+ * Called when option 'background' or 'termguicolors' was set,
+ * or when any highlight is changed.
  */
     void
 term_update_colors_all(void)
 {
-    term_T *tp;
-
-    FOR_ALL_TERMS(tp)
-	term_update_colors(tp);
+    term_T *term;
+
+    FOR_ALL_TERMS(term)
+    {
+	if (term->tl_vterm == NULL)
+	    continue;
+	init_default_colors(term);
+	vterm_state_set_default_colors(
+		vterm_obtain_state(term->tl_vterm),
+		&term->tl_default_color.fg,
+		&term->tl_default_color.bg);
+    }
 }
 
 /*
@@ -4692,8 +4712,8 @@ term_get_buf(typval_T *argvars, char *wh
 clear_cell(VTermScreenCell *cell)
 {
     CLEAR_FIELD(*cell);
-    cell->fg.type = VTERM_COLOR_DEFAULT_FG;
-    cell->bg.type = VTERM_COLOR_DEFAULT_BG;
+    cell->fg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
+    cell->bg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
 }
 
     static void
@@ -4844,8 +4864,8 @@ f_term_dumpwrite(typval_T *argvars, typv
 		if (should_break)
 		    break;
 	    }
-	    same_attr = vtermAttr2hl(cell.attrs)
-					       == vtermAttr2hl(prev_cell.attrs)
+	    same_attr = vtermAttr2hl(&cell.attrs)
+					      == vtermAttr2hl(&prev_cell.attrs)
 			&& vterm_color_is_equal(&cell.fg, &prev_cell.fg)
 			&& vterm_color_is_equal(&cell.bg, &prev_cell.bg);
 	    if (same_chars && cell.width == prev_cell.width && same_attr
@@ -4893,7 +4913,7 @@ f_term_dumpwrite(typval_T *argvars, typv
 		    }
 		    else
 		    {
-			fprintf(fd, "%d", vtermAttr2hl(cell.attrs));
+			fprintf(fd, "%d", vtermAttr2hl(&cell.attrs));
 			if (vterm_color_is_equal(&cell.fg, &prev_cell.fg))
 			    fputs("&", fd);
 			else
@@ -5344,7 +5364,7 @@ term_load_dump(typval_T *argvars, typval
 	VTermPos	cursor_pos1;
 	VTermPos	cursor_pos2;
 
-	init_default_colors(term, NULL);
+	init_default_colors(term);
 
 	rettv->vval.v_number = buf->b_fnum;
 
@@ -5454,8 +5474,8 @@ term_load_dump(typval_T *argvars, typval
 			else if (!vterm_color_is_equal(&(cellattr1 + col)->bg,
 						   &(cellattr2 + col)->bg))
 			    textline[col] = 'b';
-			else if (vtermAttr2hl((cellattr1 + col)->attrs)
-				   != vtermAttr2hl(((cellattr2 + col)->attrs)))
+			else if (vtermAttr2hl(&(cellattr1 + col)->attrs)
+				  != vtermAttr2hl(&((cellattr2 + col)->attrs)))
 			    textline[col] = 'a';
 		    }
 		    p1 += len1;
@@ -6134,7 +6154,8 @@ f_term_scrape(typval_T *argvars, typval_
 				     bg.red, bg.green, bg.blue);
 	dict_add_string(dcell, "bg", rgb);
 
-	dict_add_number(dcell, "attr", cell2attr(term, NULL, attrs, fg, bg));
+	dict_add_number(dcell, "attr",
+				      cell2attr(term, NULL, &attrs, &fg, &bg));
 	dict_add_number(dcell, "width", width);
 
 	++pos.col;
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_MyTermCol.dump
@@ -0,0 +1,15 @@
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_MyTermCol_over_Terminal.dump
@@ -0,0 +1,15 @@
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_MyWinCol.dump
@@ -0,0 +1,15 @@
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#ff404010#e0e0004@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_MyWinCol_over_group.dump
@@ -0,0 +1,15 @@
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#ff404010#e0e0004@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_Terminal.dump
@@ -0,0 +1,15 @@
+|h+0#4040ff13#ffff4012|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#4040ff13#ffff4012|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#4040ff13#ffff4012@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_gui_MyTermCol.dump
@@ -0,0 +1,15 @@
+|h+0#007800255#6789ff255|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#007800255#6789ff255|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#007800255#6789ff255@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#007800255#6789ff255@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff255#006400255|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_gui_MyWinCol.dump
@@ -0,0 +1,15 @@
+|h+0#fe1122255#818100255|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#fe1122255#818100255|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#fe1122255#818100255@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#fe1122255#818100255@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff255#006400255|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_gui_Terminal.dump
@@ -0,0 +1,15 @@
+|h+0#3344ff255#b0a700255|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#3344ff255#b0a700255|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|5+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|6+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|7+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|8+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#3344ff255#b0a700255@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+2#ffffff255#006400255|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_gui_transp_MyTermCol.dump
@@ -0,0 +1,15 @@
+|h+0#007800255#ffffff0|e|l@1|o| @31||+1#0000000&|0+0&&| @35
+|h+0#007800255&|e|l@1|o| @31||+1#0000000&|1+0&&| @35
+> +0#007800255&@36||+1#0000000&|2+0&&| @35
+| +0#007800255&@36||+1#0000000&|3+0&&| @35
+| +0#007800255&@36||+1#0000000&|4+0&&| @35
+| +0#007800255&@36||+1#0000000&|5+0&&| @35
+| +0#007800255&@36||+1#0000000&|6+0&&| @35
+| +0#007800255&@36||+1#0000000&|7+0&&| @35
+| +0#007800255&@36||+1#0000000&|8+0&&| @35
+| +0#007800255&@36||+1#0000000&|9+0&&| @35
+| +0#007800255&@36||+1#0000000&|1+0&&|0| @34
+| +0#007800255&@36||+1#0000000&|1+0&&@1| @34
+| +0#007800255&@36||+1#0000000&|1+0&&|2| @34
+|!+2#ffffff255#006400255|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_gui_transp_MyWinCol.dump
@@ -0,0 +1,15 @@
+|h+0#fe1122255#ffffff0|e|l@1|o| @31||+1#0000000&|0+0&&| @35
+|h+0#fe1122255&|e|l@1|o| @31||+1#0000000&|1+0&&| @35
+> +0#fe1122255&@36||+1#0000000&|2+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|3+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|4+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|5+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|6+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|7+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|8+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|9+0&&| @35
+| +0#fe1122255&@36||+1#0000000&|1+0&&|0| @34
+| +0#fe1122255&@36||+1#0000000&|1+0&&@1| @34
+| +0#fe1122255&@36||+1#0000000&|1+0&&|2| @34
+|!+2#ffffff255#006400255|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_gui_transp_Terminal.dump
@@ -0,0 +1,15 @@
+|h+0#3344ff255#ffffff0|e|l@1|o| @31||+1#0000000&|0+0&&| @35
+|h+0#3344ff255&|e|l@1|o| @31||+1#0000000&|1+0&&| @35
+> +0#3344ff255&@36||+1#0000000&|2+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|3+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|4+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|5+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|6+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|7+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|8+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|9+0&&| @35
+| +0#3344ff255&@36||+1#0000000&|1+0&&|0| @34
+| +0#3344ff255&@36||+1#0000000&|1+0&&@1| @34
+| +0#3344ff255&@36||+1#0000000&|1+0&&|2| @34
+|!+2#ffffff255#006400255|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_transp_MyTermCol.dump
@@ -0,0 +1,15 @@
+|h+0#00e0003#ffffff0|e|l@1|o| @31||+1#0000000&|0+0&&| @35
+|h+0#00e0003&|e|l@1|o| @31||+1#0000000&|1+0&&| @35
+> +0#00e0003&@36||+1#0000000&|2+0&&| @35
+| +0#00e0003&@36||+1#0000000&|3+0&&| @35
+| +0#00e0003&@36||+1#0000000&|4+0&&| @35
+| +0#00e0003&@36||+1#0000000&|5+0&&| @35
+| +0#00e0003&@36||+1#0000000&|6+0&&| @35
+| +0#00e0003&@36||+1#0000000&|7+0&&| @35
+| +0#00e0003&@36||+1#0000000&|8+0&&| @35
+| +0#00e0003&@36||+1#0000000&|9+0&&| @35
+| +0#00e0003&@36||+1#0000000&|1+0&&|0| @34
+| +0#00e0003&@36||+1#0000000&|1+0&&@1| @34
+| +0#00e0003&@36||+1#0000000&|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_transp_MyWinCol.dump
@@ -0,0 +1,15 @@
+|h+0#ff404010#ffffff0|e|l@1|o| @31||+1#0000000&|0+0&&| @35
+|h+0#ff404010&|e|l@1|o| @31||+1#0000000&|1+0&&| @35
+> +0#ff404010&@36||+1#0000000&|2+0&&| @35
+| +0#ff404010&@36||+1#0000000&|3+0&&| @35
+| +0#ff404010&@36||+1#0000000&|4+0&&| @35
+| +0#ff404010&@36||+1#0000000&|5+0&&| @35
+| +0#ff404010&@36||+1#0000000&|6+0&&| @35
+| +0#ff404010&@36||+1#0000000&|7+0&&| @35
+| +0#ff404010&@36||+1#0000000&|8+0&&| @35
+| +0#ff404010&@36||+1#0000000&|9+0&&| @35
+| +0#ff404010&@36||+1#0000000&|1+0&&|0| @34
+| +0#ff404010&@36||+1#0000000&|1+0&&@1| @34
+| +0#ff404010&@36||+1#0000000&|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_color_transp_Terminal.dump
@@ -0,0 +1,15 @@
+|h+0#4040ff13#ffffff0|e|l@1|o| @31||+1#0000000&|0+0&&| @35
+|h+0#4040ff13&|e|l@1|o| @31||+1#0000000&|1+0&&| @35
+> +0#4040ff13&@36||+1#0000000&|2+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|3+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|4+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|5+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|6+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|7+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|8+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|9+0&&| @35
+| +0#4040ff13&@36||+1#0000000&|1+0&&|0| @34
+| +0#4040ff13&@36||+1#0000000&|1+0&&@1| @34
+| +0#4040ff13&@36||+1#0000000&|1+0&&|2| @34
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|c|a|l@1| |O|p|e|n|T|e|r|m|(|)| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_MyPopupHlCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#40ffff15#40ff4011|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#40ffff15#40ff4011|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|6| @24|║+0#40ffff15#40ff4011|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|7| @24|║+0#40ffff15#40ff4011> @19|║| +0#0000000#ffffff0@26
+|8| @24|║+0#40ffff15#40ff4011| @19|║| +0#0000000#ffffff0@26
+|9| @24|║+0#40ffff15#40ff4011| @19|║| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#40ffff15#40ff4011|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_MyTermCol_over_Terminal.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#0000001#ffd7ff255|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#0000001#ffd7ff255|h+0#00e0003#5fd7ff255|e|l@1|o| @14|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|6| @24|║+0#0000001#ffd7ff255|h+0#00e0003#5fd7ff255|e|l@1|o| @14|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|7| @24|║+0#0000001#ffd7ff255> +0#00e0003#5fd7ff255@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|8| @24|║+0#0000001#ffd7ff255| +0#00e0003#5fd7ff255@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|9| @24|║+0#0000001#ffd7ff255| +0#00e0003#5fd7ff255@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#0000001#ffd7ff255|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_MyWinCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#ff404010#e0e0004|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#ff404010#e0e0004|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|6| @24|║+0#ff404010#e0e0004|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|7| @24|║+0#ff404010#e0e0004> @19|║| +0#0000000#ffffff0@26
+|8| @24|║+0#ff404010#e0e0004| @19|║| +0#0000000#ffffff0@26
+|9| @24|║+0#ff404010#e0e0004| @19|║| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#ff404010#e0e0004|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_MyWinCol_over_group.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#ff404010#e0e0004|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#ff404010#e0e0004|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|6| @24|║+0#ff404010#e0e0004|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|7| @24|║+0#ff404010#e0e0004> @19|║| +0#0000000#ffffff0@26
+|8| @24|║+0#ff404010#e0e0004| @19|║| +0#0000000#ffffff0@26
+|9| @24|║+0#ff404010#e0e0004| @19|║| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#ff404010#e0e0004|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_MyPopupHlCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#00e8f0255#126521255|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#00e8f0255#126521255|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|6| @24|║+0#00e8f0255#126521255|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|7| @24|║+0#00e8f0255#126521255> @19|║| +0#0000000#ffffff0@26
+|8| @24|║+0#00e8f0255#126521255| @19|║| +0#0000000#ffffff0@26
+|9| @24|║+0#00e8f0255#126521255| @19|║| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#00e8f0255#126521255|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_MyTermCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0&#ff8bff255|═@19|╗| +0&#ffffff0@26
+|5| @24|║+0&#ff8bff255|h+0#007800255#6789ff255|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|6| @24|║+0&#ff8bff255|h+0#007800255#6789ff255|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|7| @24|║+0&#ff8bff255> +0#007800255#6789ff255@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|8| @24|║+0&#ff8bff255| +0#007800255#6789ff255@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|9| @24|║+0&#ff8bff255| +0#007800255#6789ff255@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|1|0| @23|╚+0&#ff8bff255|═@19|╝| +0&#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_MyWinCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#fe1122255#818100255|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#fe1122255#818100255|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|6| @24|║+0#fe1122255#818100255|h|e|l@1|o| @14|║| +0#0000000#ffffff0@26
+|7| @24|║+0#fe1122255#818100255> @19|║| +0#0000000#ffffff0@26
+|8| @24|║+0#fe1122255#818100255| @19|║| +0#0000000#ffffff0@26
+|9| @24|║+0#fe1122255#818100255| @19|║| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#fe1122255#818100255|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_Terminal.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0&#ff8bff255|═@19|╗| +0&#ffffff0@26
+|5| @24|║+0&#ff8bff255|h+0#3344ff255#b0a700255|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|6| @24|║+0&#ff8bff255|h+0#3344ff255#b0a700255|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|7| @24|║+0&#ff8bff255> +0#3344ff255#b0a700255@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|8| @24|║+0&#ff8bff255| +0#3344ff255#b0a700255@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|9| @24|║+0&#ff8bff255| +0#3344ff255#b0a700255@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|1|0| @23|╚+0&#ff8bff255|═@19|╝| +0&#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_transp_MyPopupHlCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#00e8f0255&|═@19|╗| +0#0000000&@26
+|5| @24|║+0#00e8f0255&|h|e|l@1|o| @14|║| +0#0000000&@26
+|6| @24|║+0#00e8f0255&|h|e|l@1|o| @14|║| +0#0000000&@26
+|7| @24|║+0#00e8f0255&> @19|║| +0#0000000&@26
+|8| @24|║+0#00e8f0255&| @19|║| +0#0000000&@26
+|9| @24|║+0#00e8f0255&| @19|║| +0#0000000&@26
+|1|0| @23|╚+0#00e8f0255&|═@19|╝| +0#0000000&@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_transp_MyTermCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0&#ff8bff255|═@19|╗| +0&#ffffff0@26
+|5| @24|║+0&#ff8bff255|h+0#007800255#ffffff0|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|6| @24|║+0&#ff8bff255|h+0#007800255#ffffff0|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|7| @24|║+0&#ff8bff255> +0#007800255#ffffff0@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|8| @24|║+0&#ff8bff255| +0#007800255#ffffff0@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|9| @24|║+0&#ff8bff255| +0#007800255#ffffff0@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|1|0| @23|╚+0&#ff8bff255|═@19|╝| +0&#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_transp_MyWinCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#fe1122255&|═@19|╗| +0#0000000&@26
+|5| @24|║+0#fe1122255&|h|e|l@1|o| @14|║| +0#0000000&@26
+|6| @24|║+0#fe1122255&|h|e|l@1|o| @14|║| +0#0000000&@26
+|7| @24|║+0#fe1122255&> @19|║| +0#0000000&@26
+|8| @24|║+0#fe1122255&| @19|║| +0#0000000&@26
+|9| @24|║+0#fe1122255&| @19|║| +0#0000000&@26
+|1|0| @23|╚+0#fe1122255&|═@19|╝| +0#0000000&@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_gui_transp_Terminal.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0&#ff8bff255|═@19|╗| +0&#ffffff0@26
+|5| @24|║+0&#ff8bff255|h+0#3344ff255#ffffff0|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|6| @24|║+0&#ff8bff255|h+0#3344ff255#ffffff0|e|l@1|o| @14|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|7| @24|║+0&#ff8bff255> +0#3344ff255#ffffff0@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|8| @24|║+0&#ff8bff255| +0#3344ff255#ffffff0@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|9| @24|║+0&#ff8bff255| +0#3344ff255#ffffff0@19|║+0#0000000#ff8bff255| +0&#ffffff0@26
+|1|0| @23|╚+0&#ff8bff255|═@19|╝| +0&#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_transp_MyPopupHlCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#40ffff15&|═@19|╗| +0#0000000&@26
+|5| @24|║+0#40ffff15&|h|e|l@1|o| @14|║| +0#0000000&@26
+|6| @24|║+0#40ffff15&|h|e|l@1|o| @14|║| +0#0000000&@26
+|7| @24|║+0#40ffff15&> @19|║| +0#0000000&@26
+|8| @24|║+0#40ffff15&| @19|║| +0#0000000&@26
+|9| @24|║+0#40ffff15&| @19|║| +0#0000000&@26
+|1|0| @23|╚+0#40ffff15&|═@19|╝| +0#0000000&@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_transp_MyTermCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#0000001#ffd7ff255|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#0000001#ffd7ff255|h+0#00e0003#ffffff0|e|l@1|o| @14|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|6| @24|║+0#0000001#ffd7ff255|h+0#00e0003#ffffff0|e|l@1|o| @14|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|7| @24|║+0#0000001#ffd7ff255> +0#00e0003#ffffff0@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|8| @24|║+0#0000001#ffd7ff255| +0#00e0003#ffffff0@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|9| @24|║+0#0000001#ffd7ff255| +0#00e0003#ffffff0@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#0000001#ffd7ff255|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_transp_MyWinCol.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#ff404010&|═@19|╗| +0#0000000&@26
+|5| @24|║+0#ff404010&|h|e|l@1|o| @14|║| +0#0000000&@26
+|6| @24|║+0#ff404010&|h|e|l@1|o| @14|║| +0#0000000&@26
+|7| @24|║+0#ff404010&> @19|║| +0#0000000&@26
+|8| @24|║+0#ff404010&| @19|║| +0#0000000&@26
+|9| @24|║+0#ff404010&| @19|║| +0#0000000&@26
+|1|0| @23|╚+0#ff404010&|═@19|╝| +0#0000000&@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_popup_transp_Terminal.dump
@@ -0,0 +1,15 @@
+|0+0&#ffffff0| @73
+|1| @73
+|2| @73
+|3| @73
+|4| @24|╔+0#0000001#ffd7ff255|═@19|╗| +0#0000000#ffffff0@26
+|5| @24|║+0#0000001#ffd7ff255|h+0#4040ff13#ffffff0|e|l@1|o| @14|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|6| @24|║+0#0000001#ffd7ff255|h+0#4040ff13#ffffff0|e|l@1|o| @14|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|7| @24|║+0#0000001#ffd7ff255> +0#4040ff13#ffffff0@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|8| @24|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|9| @24|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@19|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26
+|1|0| @23|╚+0#0000001#ffd7ff255|═@19|╝| +0#0000000#ffffff0@26
+|1@1| @72
+|1|2| @72
+|1|3| @72
+@75
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_wincolor_split_MyWinCol.dump
@@ -0,0 +1,15 @@
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+> +0#ff404010#e0e0004@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0|5+0&&| @35
+|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @22||+1#0000000#ffffff0|6+0&&| @35
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|7+0&&| @35
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|8+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|9+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&|0| @34
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&@1| @34
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|1+0&&|2| @34
+|!+0#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|s|e|t| |w|i|n|c|o|l|o|r|=|M|y|W|i|n|C|o|l| @52
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_wincolor_split_MyWinCol2.dump
@@ -0,0 +1,15 @@
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|h+0#0000001#4040ff13|e|l@1|o| @31
+|h+0#ff404010#e0e0004|e|l@1|o| @31||+1#0000000#ffffff0|h+0#0000001#4040ff13|e|l@1|o| @31
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0> +0#0000001#4040ff13@36
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0| +0#0000001#4040ff13@36
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0| +0#0000001#4040ff13@36
+| +0#ff404010#e0e0004@36||+1#0000000#ffffff0| +0#0000001#4040ff13@36
+|!+0#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @22||+1#0000000#ffffff0|!+2#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @22
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|0+0&&| @35
+|h+0#00e0003#5fd7ff255|e|l@1|o| @31||+1#0000000#ffffff0|1+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|2+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|3+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|4+0&&| @35
+| +0#00e0003#5fd7ff255@36||+1#0000000#ffffff0|5+0&&| @35
+|!+0#ffffff16#00e0003|c|a|t| |[|r|u|n@1|i|n|g|]| @23|[+1#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @23
+|:+0&&|s|e|t| |w|i|n|c|o|l|o|r|=|M|y|W|i|n|C|o|l|2| @51
--- a/src/testdir/test_terminal3.vim
+++ b/src/testdir/test_terminal3.vim
@@ -66,6 +66,177 @@ func Test_terminal_invalid_arg()
   call assert_fails('terminal ++xyz', 'E181:')
 endfunc
 
+" Check a terminal with different colors
+func Terminal_color(group_name, highlight_cmds, highlight_opt, open_cmds)
+  CheckRunVimInTerminal
+  CheckUnix
+
+  let lines = [
+	\ 'call setline(1, range(20))',
+	\ 'func OpenTerm()',
+	\ '  set noruler',
+	\ "  call term_start('cat', #{vertical: 1, " .. a:highlight_opt .. "})",
+	\ ] + a:open_cmds + [
+	\ 'endfunc',
+	\ ] + a:highlight_cmds
+  call writefile(lines, 'XtermStart')
+  let buf = RunVimInTerminal('-S XtermStart', #{rows: 15})
+  call TermWait(buf, 100)
+  call term_sendkeys(buf, ":call OpenTerm()\<CR>")
+  call TermWait(buf, 50)
+  call term_sendkeys(buf, "hello\<CR>")
+  call VerifyScreenDump(buf, 'Test_terminal_color_' .. a:group_name, {})
+
+  call term_sendkeys(buf, "\<C-D>")
+  call TermWait(buf, 50)
+  call StopVimInTerminal(buf)
+  call delete('XtermStart')
+endfunc
+
+func Test_terminal_color_Terminal()
+  call Terminal_color("Terminal", [
+  \ "highlight Terminal ctermfg=blue ctermbg=yellow",
+  \ ], "", [])
+endfunc
+
+func Test_terminal_color_group()
+  call Terminal_color("MyTermCol", [
+  \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
+  \ ], "term_highlight: 'MyTermCol',", [])
+endfunc
+
+func Test_terminal_color_wincolor()
+  call Terminal_color("MyWinCol", [
+  \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
+  \ ], "", [
+  \ 'set wincolor=MyWinCol',
+  \ ])
+endfunc
+
+func Test_terminal_color_group_over_Terminal()
+  call Terminal_color("MyTermCol_over_Terminal", [
+  \ "highlight Terminal ctermfg=blue ctermbg=yellow",
+  \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
+  \ ], "term_highlight: 'MyTermCol',", [])
+endfunc
+
+func Test_terminal_color_wincolor_over_group()
+  call Terminal_color("MyWinCol_over_group", [
+  \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
+  \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
+  \ ], "term_highlight: 'MyTermCol',", [
+  \ 'set wincolor=MyWinCol',
+  \ ])
+endfunc
+
+func Test_terminal_color_wincolor_split()
+  CheckRunVimInTerminal
+  CheckUnix
+
+  let lines = [
+	\ 'call setline(1, range(20))',
+	\ 'func OpenTerm()',
+	\ '  set noruler',
+	\ "  call term_start('cat', #{vertical: 1, term_highlight: 'MyTermCol'})",
+	\ 'endfunc',
+  \ 'highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue',
+  \ 'highlight MyWinCol ctermfg=red ctermbg=darkyellow',
+  \ 'highlight MyWinCol2 ctermfg=black ctermbg=blue',
+	\ ]
+  call writefile(lines, 'XtermStart')
+  let buf = RunVimInTerminal('-S XtermStart', #{rows: 15})
+  call TermWait(buf, 100)
+  call term_sendkeys(buf, ":call OpenTerm()\<CR>")
+  call TermWait(buf, 50)
+  call term_sendkeys(buf, "hello\<CR>")
+  call TermWait(buf, 50)
+
+  call term_sendkeys(buf, "\<C-W>:split\<CR>")
+  call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol\<CR>")
+  call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol', {})
+
+  call term_sendkeys(buf, "\<C-W>b:2sb\<CR>")
+  call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol2\<CR>")
+  call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol2', {})
+
+  call term_sendkeys(buf, "\<C-D>")
+  call TermWait(buf, 50)
+  call StopVimInTerminal(buf)
+  call delete('XtermStart')
+endfunc
+
+func Test_terminal_color_transp_Terminal()
+  call Terminal_color("transp_Terminal", [
+  \ "highlight Terminal ctermfg=blue",
+  \ ], "", [])
+endfunc
+
+func Test_terminal_color_transp_group()
+  call Terminal_color("transp_MyTermCol", [
+  \ "highlight MyTermCol ctermfg=darkgreen",
+  \ ], "term_highlight: 'MyTermCol',", [])
+endfunc
+
+func Test_terminal_color_transp_wincolor()
+  call Terminal_color("transp_MyWinCol", [
+  \ "highlight MyWinCol ctermfg=red",
+  \ ], "", [
+  \ 'set wincolor=MyWinCol',
+  \ ])
+endfunc
+
+func Test_terminal_color_gui_Terminal()
+  CheckFeature termguicolors
+  call Terminal_color("gui_Terminal", [
+  \ "set termguicolors",
+  \ "highlight Terminal guifg=#3344ff guibg=#b0a700",
+  \ ], "", [])
+endfunc
+
+func Test_terminal_color_gui_group()
+  CheckFeature termguicolors
+  call Terminal_color("gui_MyTermCol", [
+  \ "set termguicolors",
+  \ "highlight MyTermCol guifg=#007800 guibg=#6789ff",
+  \ ], "term_highlight: 'MyTermCol',", [])
+endfunc
+
+func Test_terminal_color_gui_wincolor()
+  CheckFeature termguicolors
+  call Terminal_color("gui_MyWinCol", [
+  \ "set termguicolors",
+  \ "highlight MyWinCol guifg=#fe1122 guibg=#818100",
+  \ ], "", [
+  \ 'set wincolor=MyWinCol',
+  \ ])
+endfunc
+
+func Test_terminal_color_gui_transp_Terminal()
+  CheckFeature termguicolors
+  call Terminal_color("gui_transp_Terminal", [
+  \ "set termguicolors",
+  \ "highlight Terminal guifg=#3344ff",
+  \ ], "", [])
+endfunc
+
+func Test_terminal_color_gui_transp_group()
+  CheckFeature termguicolors
+  call Terminal_color("gui_transp_MyTermCol", [
+  \ "set termguicolors",
+  \ "highlight MyTermCol guifg=#007800",
+  \ ], "term_highlight: 'MyTermCol',", [])
+endfunc
+
+func Test_terminal_color_gui_transp_wincolor()
+  CheckFeature termguicolors
+  call Terminal_color("gui_transp_MyWinCol", [
+  \ "set termguicolors",
+  \ "highlight MyWinCol guifg=#fe1122",
+  \ ], "", [
+  \ 'set wincolor=MyWinCol',
+  \ ])
+endfunc
+
 func Test_terminal_in_popup()
   CheckRunVimInTerminal
 
@@ -180,7 +351,7 @@ func Test_terminal_in_popup_min_size()
 endfunc
 
 " Check a terminal in popup window with different colors
-func Terminal_in_popup_colored(group_name, highlight_cmd, highlight_opt)
+func Terminal_in_popup_color(group_name, highlight_cmds, highlight_opt, popup_cmds, popup_opt)
   CheckRunVimInTerminal
   CheckUnix
 
@@ -189,10 +360,11 @@ func Terminal_in_popup_colored(group_nam
 	\ 'func OpenTerm()',
 	\ "  let s:buf = term_start('cat', #{hidden: 1, "
 	\ .. a:highlight_opt .. "})",
-	\ '  let g:winid = popup_create(s:buf, #{ border: []})',
+	\ '  let g:winid = popup_create(s:buf, #{border: [], '
+  \ .. a:popup_opt .. '})',
+  \ ] + a:popup_cmds + [
 	\ 'endfunc',
-	\ a:highlight_cmd,
-	\ ]
+	\ ] + a:highlight_cmds
   call writefile(lines, 'XtermPopup')
   let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
   call TermWait(buf, 100)
@@ -210,12 +382,140 @@ func Terminal_in_popup_colored(group_nam
   call delete('XtermPopup')
 endfunc
 
-func Test_terminal_in_popup_colored_Terminal()
-  call Terminal_in_popup_colored("Terminal", "highlight Terminal ctermfg=blue ctermbg=yellow", "")
+func Test_terminal_in_popup_color_Terminal()
+  call Terminal_in_popup_color("Terminal", [
+  \ "highlight Terminal ctermfg=blue ctermbg=yellow",
+  \ ], "", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_group()
+  call Terminal_in_popup_color("MyTermCol", [
+  \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
+  \ ], "term_highlight: 'MyTermCol',", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_wincolor()
+  call Terminal_in_popup_color("MyWinCol", [
+  \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
+  \ ], "", [
+  \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
+  \ ], "")
+endfunc
+
+func Test_terminal_in_popup_color_popup_highlight()
+  call Terminal_in_popup_color("MyPopupHlCol", [
+  \ "highlight MyPopupHlCol ctermfg=cyan ctermbg=green",
+  \ ], "", [], "highlight: 'MyPopupHlCol'")
+endfunc
+
+func Test_terminal_in_popup_color_group_over_Terminal()
+  call Terminal_in_popup_color("MyTermCol_over_Terminal", [
+  \ "highlight Terminal ctermfg=blue ctermbg=yellow",
+  \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
+  \ ], "term_highlight: 'MyTermCol',", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_wincolor_over_group()
+  call Terminal_in_popup_color("MyWinCol_over_group", [
+  \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
+  \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
+  \ ], "term_highlight: 'MyTermCol',", [
+  \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
+  \ ], "")
+endfunc
+
+func Test_terminal_in_popup_color_transp_Terminal()
+  call Terminal_in_popup_color("transp_Terminal", [
+  \ "highlight Terminal ctermfg=blue",
+  \ ], "", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_transp_group()
+  call Terminal_in_popup_color("transp_MyTermCol", [
+  \ "highlight MyTermCol ctermfg=darkgreen",
+  \ ], "term_highlight: 'MyTermCol',", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_transp_wincolor()
+  call Terminal_in_popup_color("transp_MyWinCol", [
+  \ "highlight MyWinCol ctermfg=red",
+  \ ], "", [
+  \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
+  \ ], "")
 endfunc
 
-func Test_terminal_in_popup_colored_group()
-  call Terminal_in_popup_colored("MyTermCol", "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", "term_highlight: 'MyTermCol',")
+func Test_terminal_in_popup_color_transp_popup_highlight()
+  call Terminal_in_popup_color("transp_MyPopupHlCol", [
+  \ "highlight MyPopupHlCol ctermfg=cyan",
+  \ ], "", [], "highlight: 'MyPopupHlCol'")
+endfunc
+
+func Test_terminal_in_popup_color_gui_Terminal()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_Terminal", [
+  \ "set termguicolors",
+  \ "highlight Terminal guifg=#3344ff guibg=#b0a700",
+  \ ], "", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_gui_group()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_MyTermCol", [
+  \ "set termguicolors",
+  \ "highlight MyTermCol guifg=#007800 guibg=#6789ff",
+  \ ], "term_highlight: 'MyTermCol',", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_gui_wincolor()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_MyWinCol", [
+  \ "set termguicolors",
+  \ "highlight MyWinCol guifg=#fe1122 guibg=#818100",
+  \ ], "", [
+  \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
+  \ ], "")
+endfunc
+
+func Test_terminal_in_popup_color_gui_popup_highlight()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_MyPopupHlCol", [
+  \ "set termguicolors",
+  \ "highlight MyPopupHlCol guifg=#00e8f0 guibg=#126521",
+  \ ], "", [], "highlight: 'MyPopupHlCol'")
+endfunc
+
+func Test_terminal_in_popup_color_gui_transp_Terminal()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_transp_Terminal", [
+  \ "set termguicolors",
+  \ "highlight Terminal guifg=#3344ff",
+  \ ], "", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_gui_transp_group()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_transp_MyTermCol", [
+  \ "set termguicolors",
+  \ "highlight MyTermCol guifg=#007800",
+  \ ], "term_highlight: 'MyTermCol',", [], "")
+endfunc
+
+func Test_terminal_in_popup_color_gui_transp_wincolor()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_transp_MyWinCol", [
+  \ "set termguicolors",
+  \ "highlight MyWinCol guifg=#fe1122",
+  \ ], "", [
+  \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
+  \ ], "")
+endfunc
+
+func Test_terminal_in_popup_color_gui_transp_popup_highlight()
+  CheckFeature termguicolors
+  call Terminal_in_popup_color("gui_transp_MyPopupHlCol", [
+  \ "set termguicolors",
+  \ "highlight MyPopupHlCol guifg=#00e8f0",
+  \ ], "", [], "highlight: 'MyPopupHlCol'")
 endfunc
 
 func Test_double_popup_terminal()
@@ -411,7 +711,7 @@ func Test_term_mouse()
   call TermWait(buf, 50)
   call assert_equal('yellow', readfile('Xbuf')[0])
 
-  " Test for selecting text using doubleclick
+  " Test for selecting text using double click
   call delete('Xbuf')
   call test_setmouse(1, 11)
   call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>")
@@ -431,7 +731,7 @@ func Test_term_mouse()
   call TermWait(buf, 50)
   call assert_equal("vim emacs sublime nano\n", readfile('Xbuf')[0])
 
-  " Test for selecting a block using qudraple click
+  " Test for selecting a block using quadruple click
   call delete('Xbuf')
   call test_setmouse(1, 11)
   call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>")
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3628,
+/**/
     3627,
 /**/
     3626,
--- a/src/window.c
+++ b/src/window.c
@@ -1422,6 +1422,9 @@ win_init(win_T *newp, win_T *oldp, int f
 #ifdef FEAT_SYN_HL
     check_colorcolumn(newp);
 #endif
+#ifdef FEAT_TERMINAL
+    term_update_wincolor(newp);
+#endif
 }
 
 /*
@@ -3684,6 +3687,9 @@ win_init_empty(win_T *wp)
 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
     wp->w_s = &wp->w_buffer->b_s;
 #endif
+#ifdef FEAT_TERMINAL
+    term_reset_wincolor(wp);
+#endif
 }
 
 /*