Mercurial > vim
comparison src/os_win32.c @ 31800:ea09e0f546f0 v9.0.1232
patch 9.0.1232: ColorTable saving and restoring does not work properly
Commit: https://github.com/vim/vim/commit/d343c60df4b0adc6b1baac4d68a72a735ac21dc4
Author: Christopher Plewright <chris@createng.com>
Date: Sun Jan 22 18:58:30 2023 +0000
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Jan 2023 20:00:06 +0100 |
parents | 3365a601e73b |
children | e279b756475b |
comparison
equal
deleted
inserted
replaced
31799:d4674c1fd5d9 | 31800:ea09e0f546f0 |
---|---|
3424 create_conin(); | 3424 create_conin(); |
3425 g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE); | 3425 g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE); |
3426 | 3426 |
3427 wt_init(); | 3427 wt_init(); |
3428 vtp_flag_init(); | 3428 vtp_flag_init(); |
3429 vtp_init(); | |
3430 # ifdef FEAT_RESTORE_ORIG_SCREEN | 3429 # ifdef FEAT_RESTORE_ORIG_SCREEN |
3431 // Save the initial console buffer for later restoration | 3430 // Save the initial console buffer for later restoration |
3432 SaveConsoleBuffer(&g_cbOrig); | 3431 SaveConsoleBuffer(&g_cbOrig); |
3433 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; | 3432 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; |
3434 # else | 3433 # else |
3460 */ | 3459 */ |
3461 if (g_fCanChangeIcon) | 3460 if (g_fCanChangeIcon) |
3462 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | 3461 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); |
3463 | 3462 |
3464 ui_get_shellsize(); | 3463 ui_get_shellsize(); |
3464 | |
3465 vtp_init(); | |
3465 | 3466 |
3466 # ifdef MCH_WRITE_DUMP | 3467 # ifdef MCH_WRITE_DUMP |
3467 fdDump = fopen("dump", "wt"); | 3468 fdDump = fopen("dump", "wt"); |
3468 | 3469 |
3469 if (fdDump) | 3470 if (fdDump) |
8454 | 8455 |
8455 static void | 8456 static void |
8456 vtp_init(void) | 8457 vtp_init(void) |
8457 { | 8458 { |
8458 # ifdef FEAT_TERMGUICOLORS | 8459 # ifdef FEAT_TERMGUICOLORS |
8459 if (!vtp_working) | 8460 CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
8460 { | 8461 csbi.cbSize = sizeof(csbi); |
8461 CONSOLE_SCREEN_BUFFER_INFOEX csbi; | 8462 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
8462 csbi.cbSize = sizeof(csbi); | 8463 save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg]; |
8463 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); | 8464 save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg]; |
8464 save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg]; | 8465 store_console_bg_rgb = save_console_bg_rgb; |
8465 save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg]; | 8466 store_console_fg_rgb = save_console_fg_rgb; |
8466 store_console_bg_rgb = save_console_bg_rgb; | 8467 |
8467 store_console_fg_rgb = save_console_fg_rgb; | 8468 COLORREF bg; |
8468 | 8469 bg = (COLORREF)csbi.ColorTable[g_color_index_bg]; |
8469 COLORREF bg; | 8470 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); |
8470 bg = (COLORREF)csbi.ColorTable[g_color_index_bg]; | 8471 default_console_color_bg = bg; |
8471 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); | 8472 |
8472 default_console_color_bg = bg; | 8473 COLORREF fg; |
8473 | 8474 fg = (COLORREF)csbi.ColorTable[g_color_index_fg]; |
8474 COLORREF fg; | 8475 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); |
8475 fg = (COLORREF)csbi.ColorTable[g_color_index_fg]; | 8476 default_console_color_fg = fg; |
8476 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); | |
8477 default_console_color_fg = fg; | |
8478 } | |
8479 # endif | 8477 # endif |
8480 use_alternate_screen_buffer = win10_22H2_or_later && p_rs && vtp_working | 8478 use_alternate_screen_buffer = win10_22H2_or_later && p_rs && vtp_working |
8481 && !mch_getenv("VIM_TERMINAL"); | 8479 && !mch_getenv("VIM_TERMINAL"); |
8482 set_console_color_rgb(); | 8480 set_console_color_rgb(); |
8483 } | 8481 } |
8665 wt_init(void) | 8663 wt_init(void) |
8666 { | 8664 { |
8667 wt_working = mch_getenv("WT_SESSION") != NULL; | 8665 wt_working = mch_getenv("WT_SESSION") != NULL; |
8668 } | 8666 } |
8669 | 8667 |
8668 int | |
8669 use_wt(void) | |
8670 { | |
8671 return USE_WT; | |
8672 } | |
8673 | |
8670 # ifdef FEAT_TERMGUICOLORS | 8674 # ifdef FEAT_TERMGUICOLORS |
8671 static int | 8675 static int |
8672 ctermtoxterm( | 8676 ctermtoxterm( |
8673 int cterm) | 8677 int cterm) |
8674 { | 8678 { |
8697 term_fg_rgb_color(fg); | 8701 term_fg_rgb_color(fg); |
8698 term_bg_rgb_color(bg); | 8702 term_bg_rgb_color(bg); |
8699 return; | 8703 return; |
8700 } | 8704 } |
8701 | 8705 |
8702 if (!conpty_working) | 8706 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); |
8703 { | 8707 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); |
8704 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); | 8708 |
8705 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); | 8709 csbi.cbSize = sizeof(csbi); |
8706 | 8710 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
8707 csbi.cbSize = sizeof(csbi); | 8711 |
8708 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); | 8712 csbi.cbSize = sizeof(csbi); |
8709 | 8713 csbi.srWindow.Right += 1; |
8710 csbi.cbSize = sizeof(csbi); | 8714 csbi.srWindow.Bottom += 1; |
8711 csbi.srWindow.Right += 1; | 8715 store_console_bg_rgb = csbi.ColorTable[g_color_index_bg]; |
8712 csbi.srWindow.Bottom += 1; | 8716 store_console_fg_rgb = csbi.ColorTable[g_color_index_fg]; |
8713 store_console_bg_rgb = csbi.ColorTable[g_color_index_bg]; | 8717 csbi.ColorTable[g_color_index_bg] = (COLORREF)bg; |
8714 store_console_fg_rgb = csbi.ColorTable[g_color_index_fg]; | 8718 csbi.ColorTable[g_color_index_fg] = (COLORREF)fg; |
8715 csbi.ColorTable[g_color_index_bg] = (COLORREF)bg; | 8719 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
8716 csbi.ColorTable[g_color_index_fg] = (COLORREF)fg; | |
8717 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi); | |
8718 } | |
8719 # endif | 8720 # endif |
8720 } | 8721 } |
8721 | 8722 |
8722 # if defined(FEAT_TERMGUICOLORS) || defined(PROTO) | 8723 # if defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
8723 void | 8724 void |
8740 if (guifg == INVALCOLOR) | 8741 if (guifg == INVALCOLOR) |
8741 { | 8742 { |
8742 ctermfg = -1; | 8743 ctermfg = -1; |
8743 if (id > 0) | 8744 if (id > 0) |
8744 syn_id2cterm_bg(id, &ctermfg, &dummynull); | 8745 syn_id2cterm_bg(id, &ctermfg, &dummynull); |
8745 if (vtp_working) | 8746 if (ctermfg != -1) |
8746 { | 8747 guifg = ctermtoxterm(ctermfg); |
8747 cterm_normal_fg_gui_color = guifg = | |
8748 ctermfg != -1 ? ctermtoxterm(ctermfg) : INVALCOLOR; | |
8749 ctermfg = ctermfg < 0 ? 0 : ctermfg; | |
8750 } | |
8751 else | 8748 else |
8752 { | 8749 guifg = USE_WT ? INVALCOLOR : default_console_color_fg; |
8753 guifg = ctermfg != -1 ? ctermtoxterm(ctermfg) | 8750 cterm_normal_fg_gui_color = guifg; |
8754 : default_console_color_fg; | 8751 ctermfg = ctermfg < 0 ? 0 : ctermfg; |
8755 cterm_normal_fg_gui_color = guifg; | |
8756 ctermfg = ctermfg < 0 ? 0 : ctermfg; | |
8757 } | |
8758 } | 8752 } |
8759 if (guibg == INVALCOLOR) | 8753 if (guibg == INVALCOLOR) |
8760 { | 8754 { |
8761 ctermbg = -1; | 8755 ctermbg = -1; |
8762 if (id > 0) | 8756 if (id > 0) |
8763 syn_id2cterm_bg(id, &dummynull, &ctermbg); | 8757 syn_id2cterm_bg(id, &dummynull, &ctermbg); |
8764 if (vtp_working) | 8758 if (ctermbg != -1) |
8765 { | 8759 guibg = ctermtoxterm(ctermbg); |
8766 cterm_normal_bg_gui_color = guibg = | |
8767 ctermbg != -1 ? ctermtoxterm(ctermbg) : INVALCOLOR; | |
8768 if (ctermbg < 0) | |
8769 ctermbg = 0; | |
8770 } | |
8771 else | 8760 else |
8772 { | 8761 guibg = USE_WT ? INVALCOLOR : default_console_color_bg; |
8773 guibg = ctermbg != -1 ? ctermtoxterm(ctermbg) | 8762 cterm_normal_bg_gui_color = guibg; |
8774 : default_console_color_bg; | 8763 ctermbg = ctermbg < 0 ? 0 : ctermbg; |
8775 cterm_normal_bg_gui_color = guibg; | |
8776 ctermbg = ctermbg < 0 ? 0 : ctermbg; | |
8777 } | |
8778 } | 8764 } |
8779 | 8765 |
8780 *cterm_fg = ctermfg; | 8766 *cterm_fg = ctermfg; |
8781 *cterm_bg = ctermbg; | 8767 *cterm_bg = ctermbg; |
8782 *gui_fg = guifg; | 8768 *gui_fg = guifg; |
8789 */ | 8775 */ |
8790 static void | 8776 static void |
8791 reset_console_color_rgb(void) | 8777 reset_console_color_rgb(void) |
8792 { | 8778 { |
8793 # ifdef FEAT_TERMGUICOLORS | 8779 # ifdef FEAT_TERMGUICOLORS |
8794 | |
8795 if (vtp_working) | |
8796 return; | |
8797 | 8780 |
8798 CONSOLE_SCREEN_BUFFER_INFOEX csbi; | 8781 CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
8799 | 8782 |
8800 csbi.cbSize = sizeof(csbi); | 8783 csbi.cbSize = sizeof(csbi); |
8801 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); | 8784 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
8814 */ | 8797 */ |
8815 static void | 8798 static void |
8816 restore_console_color_rgb(void) | 8799 restore_console_color_rgb(void) |
8817 { | 8800 { |
8818 # ifdef FEAT_TERMGUICOLORS | 8801 # ifdef FEAT_TERMGUICOLORS |
8819 if (vtp_working) | |
8820 return; | |
8821 | 8802 |
8822 CONSOLE_SCREEN_BUFFER_INFOEX csbi; | 8803 CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
8823 | 8804 |
8824 csbi.cbSize = sizeof(csbi); | 8805 csbi.cbSize = sizeof(csbi); |
8825 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); | 8806 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |