patch 9.0.1232: ColorTable saving and restoring does not work properly
Problem: ColorTable saving and restoring does not work properly.
Solution: Restore ColorTable[16] usage. (Christopher Plewright,
closes #11836)
diff --git a/src/os_win32.c b/src/os_win32.c
index 8a254f8..ba5d228 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -3426,7 +3426,6 @@
wt_init();
vtp_flag_init();
- vtp_init();
# ifdef FEAT_RESTORE_ORIG_SCREEN
// Save the initial console buffer for later restoration
SaveConsoleBuffer(&g_cbOrig);
@@ -3463,6 +3462,8 @@
ui_get_shellsize();
+ vtp_init();
+
# ifdef MCH_WRITE_DUMP
fdDump = fopen("dump", "wt");
@@ -8456,26 +8457,23 @@
vtp_init(void)
{
# ifdef FEAT_TERMGUICOLORS
- if (!vtp_working)
- {
- CONSOLE_SCREEN_BUFFER_INFOEX csbi;
- csbi.cbSize = sizeof(csbi);
- GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
- save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg];
- save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg];
- store_console_bg_rgb = save_console_bg_rgb;
- store_console_fg_rgb = save_console_fg_rgb;
+ CONSOLE_SCREEN_BUFFER_INFOEX csbi;
+ csbi.cbSize = sizeof(csbi);
+ GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
+ save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg];
+ save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg];
+ store_console_bg_rgb = save_console_bg_rgb;
+ store_console_fg_rgb = save_console_fg_rgb;
- COLORREF bg;
- bg = (COLORREF)csbi.ColorTable[g_color_index_bg];
- bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
- default_console_color_bg = bg;
+ COLORREF bg;
+ bg = (COLORREF)csbi.ColorTable[g_color_index_bg];
+ bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
+ default_console_color_bg = bg;
- COLORREF fg;
- fg = (COLORREF)csbi.ColorTable[g_color_index_fg];
- fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
- default_console_color_fg = fg;
- }
+ COLORREF fg;
+ fg = (COLORREF)csbi.ColorTable[g_color_index_fg];
+ fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
+ default_console_color_fg = fg;
# endif
use_alternate_screen_buffer = win10_22H2_or_later && p_rs && vtp_working
&& !mch_getenv("VIM_TERMINAL");
@@ -8667,6 +8665,12 @@
wt_working = mch_getenv("WT_SESSION") != NULL;
}
+ int
+use_wt(void)
+{
+ return USE_WT;
+}
+
# ifdef FEAT_TERMGUICOLORS
static int
ctermtoxterm(
@@ -8699,23 +8703,20 @@
return;
}
- if (!conpty_working)
- {
- fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
- bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
+ fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
+ bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
- csbi.cbSize = sizeof(csbi);
- GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
+ csbi.cbSize = sizeof(csbi);
+ GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
- csbi.cbSize = sizeof(csbi);
- csbi.srWindow.Right += 1;
- csbi.srWindow.Bottom += 1;
- store_console_bg_rgb = csbi.ColorTable[g_color_index_bg];
- store_console_fg_rgb = csbi.ColorTable[g_color_index_fg];
- csbi.ColorTable[g_color_index_bg] = (COLORREF)bg;
- csbi.ColorTable[g_color_index_fg] = (COLORREF)fg;
- SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
- }
+ csbi.cbSize = sizeof(csbi);
+ csbi.srWindow.Right += 1;
+ csbi.srWindow.Bottom += 1;
+ store_console_bg_rgb = csbi.ColorTable[g_color_index_bg];
+ store_console_fg_rgb = csbi.ColorTable[g_color_index_fg];
+ csbi.ColorTable[g_color_index_bg] = (COLORREF)bg;
+ csbi.ColorTable[g_color_index_fg] = (COLORREF)fg;
+ SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
# endif
}
@@ -8742,39 +8743,24 @@
ctermfg = -1;
if (id > 0)
syn_id2cterm_bg(id, &ctermfg, &dummynull);
- if (vtp_working)
- {
- cterm_normal_fg_gui_color = guifg =
- ctermfg != -1 ? ctermtoxterm(ctermfg) : INVALCOLOR;
- ctermfg = ctermfg < 0 ? 0 : ctermfg;
- }
+ if (ctermfg != -1)
+ guifg = ctermtoxterm(ctermfg);
else
- {
- guifg = ctermfg != -1 ? ctermtoxterm(ctermfg)
- : default_console_color_fg;
- cterm_normal_fg_gui_color = guifg;
- ctermfg = ctermfg < 0 ? 0 : ctermfg;
- }
+ guifg = USE_WT ? INVALCOLOR : default_console_color_fg;
+ cterm_normal_fg_gui_color = guifg;
+ ctermfg = ctermfg < 0 ? 0 : ctermfg;
}
if (guibg == INVALCOLOR)
{
ctermbg = -1;
if (id > 0)
syn_id2cterm_bg(id, &dummynull, &ctermbg);
- if (vtp_working)
- {
- cterm_normal_bg_gui_color = guibg =
- ctermbg != -1 ? ctermtoxterm(ctermbg) : INVALCOLOR;
- if (ctermbg < 0)
- ctermbg = 0;
- }
+ if (ctermbg != -1)
+ guibg = ctermtoxterm(ctermbg);
else
- {
- guibg = ctermbg != -1 ? ctermtoxterm(ctermbg)
- : default_console_color_bg;
- cterm_normal_bg_gui_color = guibg;
- ctermbg = ctermbg < 0 ? 0 : ctermbg;
- }
+ guibg = USE_WT ? INVALCOLOR : default_console_color_bg;
+ cterm_normal_bg_gui_color = guibg;
+ ctermbg = ctermbg < 0 ? 0 : ctermbg;
}
*cterm_fg = ctermfg;
@@ -8792,9 +8778,6 @@
{
# ifdef FEAT_TERMGUICOLORS
- if (vtp_working)
- return;
-
CONSOLE_SCREEN_BUFFER_INFOEX csbi;
csbi.cbSize = sizeof(csbi);
@@ -8816,8 +8799,6 @@
restore_console_color_rgb(void)
{
# ifdef FEAT_TERMGUICOLORS
- if (vtp_working)
- return;
CONSOLE_SCREEN_BUFFER_INFOEX csbi;
diff --git a/src/proto/os_win32.pro b/src/proto/os_win32.pro
index 9f8b969..6673c78 100644
--- a/src/proto/os_win32.pro
+++ b/src/proto/os_win32.pro
@@ -73,6 +73,7 @@
void fix_arg_enc(void);
int mch_setenv(char *var, char *value, int x);
int vtp_printf(char *format, ...);
+int use_wt(void);
void get_default_console_color(int *cterm_fg, int *cterm_bg, guicolor_T *gui_fg, guicolor_T *gui_bg);
void control_console_color_rgb(void);
int use_vtp(void);
diff --git a/src/term.c b/src/term.c
index ab42afb..54da3d7 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3222,7 +3222,7 @@
vim_snprintf(buf, MAX_COLOR_STR_LEN,
(char *)s, RED(rgb), GREEN(rgb), BLUE(rgb));
#ifdef FEAT_VTP
- if (has_vtp_working())
+ if (use_wt())
{
out_flush();
buf[1] = '[';
diff --git a/src/version.c b/src/version.c
index 0d595db..6604e01 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1232,
+/**/
1231,
/**/
1230,