To: vim_dev@googlegroups.com Subject: Patch 9.0.1252 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1252 Problem: MS-Windows: scrollback cropped off on Vim exit. Solution: Don't call SetConsoleScreenBufferInfoEx when using the alternate screen buffer. (Christopher Plewright, closes #11882) Files: src/os_win32.c *** ../vim-9.0.1251/src/os_win32.c 2023-01-27 21:03:08.899101847 +0000 --- src/os_win32.c 2023-01-28 10:27:32.854162029 +0000 *************** *** 232,238 **** static guicolor_T store_console_fg_rgb; static int default_console_color_bg = 0x000000; // black static int default_console_color_fg = 0xc0c0c0; // white ! # define USE_VTP (vtp_working && is_term_win32()) # define USE_WT (wt_working) # else # define USE_VTP 0 --- 232,239 ---- static guicolor_T store_console_fg_rgb; static int default_console_color_bg = 0x000000; // black static int default_console_color_fg = 0xc0c0c0; // white ! # define USE_VTP (vtp_working && is_term_win32() \ ! && (p_tgc || t_colors >= 256)) # define USE_WT (wt_working) # else # define USE_VTP 0 *************** *** 3463,3468 **** --- 3464,3472 ---- ui_get_shellsize(); vtp_init(); + // Switch to a new alternate screen buffer. + if (use_alternate_screen_buffer) + vtp_printf("\033[?1049h"); # ifdef MCH_WRITE_DUMP fdDump = fopen("dump", "wt"); *************** *** 4437,4442 **** --- 4441,4449 ---- HANDLE hConsole, COORD coordScreen) { + if (use_alternate_screen_buffer) + return; + if (!SetConsoleScreenBufferSize(hConsole, coordScreen)) { # ifdef MCH_WRITE_DUMP *************** *** 6189,6200 **** if (g_fTermcapMode) return; - // VTP uses alternate screen buffer. - // Switch to a new alternate screen buffer. - // But, not if running in a nested terminal - if (use_alternate_screen_buffer) - vtp_printf("\033[?1049h"); - SaveConsoleBuffer(&g_cbNonTermcap); if (g_cbTermcap.IsValid) --- 6196,6201 ---- *************** *** 6273,6279 **** RestoreConsoleBuffer(cb, p_rs); restore_console_color_rgb(); - // VTP uses alternate screen buffer. // Switch back to main screen buffer. if (exiting && use_alternate_screen_buffer) vtp_printf("\033[?1049l"); --- 6274,6279 ---- *************** *** 6285,6293 **** */ coord.X = 0; coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); ! if (!vtp_working) ! FillConsoleOutputCharacter(g_hConOut, ' ', ! cb->Info.dwSize.X, coord, &dwDummy); /* * The following is just for aesthetics. If we are exiting without * restoring the screen, then we want to have a prompt string --- 6285,6292 ---- */ coord.X = 0; coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); ! FillConsoleOutputCharacter(g_hConOut, ' ', ! cb->Info.dwSize.X, coord, &dwDummy); /* * The following is just for aesthetics. If we are exiting without * restoring the screen, then we want to have a prompt string *************** *** 6497,6507 **** clip.Bottom = g_srScrollRegion.Bottom; fill.Char.AsciiChar = ' '; ! if (!(vtp_working ! # ifdef FEAT_TERMGUICOLORS ! && (p_tgc || t_colors >= 256) ! # endif ! )) fill.Attributes = g_attrCurrent; else fill.Attributes = g_attrDefault; --- 6496,6502 ---- clip.Bottom = g_srScrollRegion.Bottom; fill.Char.AsciiChar = ' '; ! if (!USE_VTP) fill.Attributes = g_attrCurrent; else fill.Attributes = g_attrDefault; *************** *** 6625,6635 **** if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) return; ! if (!(vtp_working ! # ifdef FEAT_TERMGUICOLORS ! && (p_tgc || t_colors >= 256) ! # endif ! )) { // There are reports of double-width characters not displayed // correctly. This workaround should fix it, similar to how it's done --- 6620,6626 ---- if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) return; ! if (!USE_VTP) { // There are reports of double-width characters not displayed // correctly. This workaround should fix it, similar to how it's done *************** *** 6883,6893 **** } } ! if (!(vtp_working ! # ifdef FEAT_TERMGUICOLORS ! && (p_tgc || t_colors >= 256) ! # endif ! )) { FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells, coord, &written); --- 6874,6880 ---- } } ! if (!USE_VTP) { FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells, coord, &written); *************** *** 6927,6937 **** } // Cursor under VTP is always in the correct position, no need to reset. ! if (!(vtp_working ! # ifdef FEAT_TERMGUICOLORS ! && (p_tgc || t_colors >= 256) ! # endif ! )) gotoxy(g_coord.X + 1, g_coord.Y + 1); return written; --- 6914,6920 ---- } // Cursor under VTP is always in the correct position, no need to reset. ! if (!USE_VTP) gotoxy(g_coord.X + 1, g_coord.Y + 1); return written; *************** *** 7227,7237 **** normvideo(); else if (argc == 1) { ! if (vtp_working ! # ifdef FEAT_TERMGUICOLORS ! && (p_tgc || t_colors >= 256) ! # endif ! ) textcolor((WORD)arg1); else textattr((WORD)arg1); --- 7210,7216 ---- normvideo(); else if (argc == 1) { ! if (USE_VTP) textcolor((WORD)arg1); else textattr((WORD)arg1); *************** *** 8440,8445 **** --- 8419,8429 ---- mode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING); if (SetConsoleMode(out, mode) == 0) vtp_working = 0; + + // VTP uses alternate screen buffer. + // But, not if running in a nested terminal + use_alternate_screen_buffer = win10_22H2_or_later && p_rs && vtp_working + && !mch_getenv("VIM_TERMINAL"); } #endif *************** *** 8485,8492 **** 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"); set_console_color_rgb(); } --- 8469,8474 ---- *************** *** 8707,8712 **** --- 8689,8697 ---- return; } + if (use_alternate_screen_buffer) + return; + fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); *************** *** 8781,8786 **** --- 8766,8773 ---- reset_console_color_rgb(void) { # ifdef FEAT_TERMGUICOLORS + if (use_alternate_screen_buffer) + return; CONSOLE_SCREEN_BUFFER_INFOEX csbi; *************** *** 8803,8808 **** --- 8790,8797 ---- restore_console_color_rgb(void) { # ifdef FEAT_TERMGUICOLORS + if (use_alternate_screen_buffer) + return; CONSOLE_SCREEN_BUFFER_INFOEX csbi; *************** *** 8875,8880 **** --- 8864,8872 ---- void resize_console_buf(void) { + if (use_alternate_screen_buffer) + return; + CONSOLE_SCREEN_BUFFER_INFO csbi; COORD coord; SMALL_RECT newsize; *** ../vim-9.0.1251/src/version.c 2023-01-27 21:03:08.899101847 +0000 --- src/version.c 2023-01-28 10:27:02.218196276 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1252, /**/ -- ERROR 047: Keyboard not found. Press RETURN to continue. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///