To: vim_dev@googlegroups.com Subject: Patch 9.0.0347 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0347 Problem: MS-Windows: cannot set cursor shape in Windows Terminal. Solution: Make cursor shape work with Windows Terminal. (Ken Takata, closes #11028, closes #6576) Files: runtime/doc/term.txt, src/os_win32.c *** ../vim-9.0.0346/runtime/doc/term.txt 2022-08-26 17:52:47.886406161 +0100 --- runtime/doc/term.txt 2022-09-01 13:18:42.771158958 +0100 *************** *** 628,637 **** *termcap-cursor-shape* *termcap-cursor-color* When Vim enters Insert mode the 't_SI' escape sequence is sent. When Vim enters Replace mode the 't_SR' escape sequence is sent if it is set, otherwise ! 't_SI' is sent. When leaving Insert mode or Replace mode 't_EI' is used. This ! can be used to change the shape or color of the cursor in Insert or Replace ! mode. These are not standard termcap/terminfo entries, you need to set them ! yourself. Example for an xterm, this changes the color of the cursor: > if &term =~ "xterm" let &t_SI = "\]12;purple\x7" --- 628,640 ---- *termcap-cursor-shape* *termcap-cursor-color* When Vim enters Insert mode the 't_SI' escape sequence is sent. When Vim enters Replace mode the 't_SR' escape sequence is sent if it is set, otherwise ! 't_SI' is sent. When leaving Insert mode or Replace mode 't_EI' is used. ! Note: When 't_EI' is not set then 't_SI' and 't_SR' will not be sent. And ! when 't_SI' or 't_SR' is not set then 't_EI' is sent only once. ! ! This can be used to change the shape or color of the cursor in Insert or ! Replace mode. These are not standard termcap/terminfo entries, you need to set ! them yourself. Example for an xterm, this changes the color of the cursor: > if &term =~ "xterm" let &t_SI = "\]12;purple\x7" *************** *** 640,645 **** --- 643,660 ---- endif NOTE: When Vim exits the shape for Normal mode will remain. The shape from before Vim started will not be restored. + + For Windows Terminal you can use something like this: > + " Note: This should be set after `set termguicolors` or `set t_Co=256`. + if &term =~ 'xterm' || &term == 'win32' + " Use DECSCUSR escape sequences + let &t_SI = "\e[5 q" " blink bar + let &t_SR = "\e[3 q" " blink underline + let &t_EI = "\e[1 q" " blink block + let &t_ti ..= "\e[1 q" " blink block + let &t_te ..= "\e[0 q" " default (depends on terminal, normally blink block) + endif + {not available when compiled without the |+cursorshape| feature} *termcap-title* *** ../vim-9.0.0346/src/os_win32.c 2022-09-01 11:31:41.971132670 +0100 --- src/os_win32.c 2022-09-01 13:14:13.551994747 +0100 *************** *** 1528,1540 **** static void mch_set_cursor_shape(int thickness) { ! CONSOLE_CURSOR_INFO ConsoleCursorInfo; ! ConsoleCursorInfo.dwSize = thickness; ! ConsoleCursorInfo.bVisible = s_cursor_visible; ! ! SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); ! if (s_cursor_visible) ! SetConsoleCursorPosition(g_hConOut, g_coord); } void --- 1528,1554 ---- static void mch_set_cursor_shape(int thickness) { ! if (USE_VTP || USE_WT) ! { ! if (*T_CSI == NUL) ! { ! // If 't_SI' is not set, use the default cursor styles. ! if (thickness < 50) ! vtp_printf("\033[3 q"); // underline ! else ! vtp_printf("\033[0 q"); // default ! } ! } ! else ! { ! CONSOLE_CURSOR_INFO ConsoleCursorInfo; ! ConsoleCursorInfo.dwSize = thickness; ! ConsoleCursorInfo.bVisible = s_cursor_visible; ! ! SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); ! if (s_cursor_visible) ! SetConsoleCursorPosition(g_hConOut, g_coord); ! } } void *************** *** 6770,6775 **** --- 6784,6804 ---- } # endif } + else if (s[0] == ESC && len >= 3-1 && s[1] == '[') + { + int l = 2; + + if (isdigit(s[l])) + l++; + if (s[l] == ' ' && s[l + 1] == 'q') + { + // DECSCUSR (cursor style) sequences + if (USE_VTP || USE_WT) + vtp_printf("%.*s", l + 2, s); // Pass through + s += l + 2; + len -= l + 1; + } + } else { // Write a single character *************** *** 7953,7959 **** if (argc == 0) { sgrfgr = sgrbgr = -1; ! vtp_printf("033[m"); return; } --- 7982,7988 ---- if (argc == 0) { sgrfgr = sgrbgr = -1; ! vtp_printf("\033[m"); return; } *** ../vim-9.0.0346/src/version.c 2022-09-01 12:58:46.584970141 +0100 --- src/version.c 2022-09-01 13:19:08.119085897 +0100 *************** *** 709,710 **** --- 709,712 ---- { /* Add new patch number below this line */ + /**/ + 347, /**/ -- Mrs Abbott: I'm a paediatrician. Basil: Feet? Mrs Abbott: Children. Sybil: Oh, Basil! Basil: Well, children have feet, don't they? That's how they move around, my dear. You must take a look next time, it's most interesting. (Fawlty Towers) /// 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 ///