# HG changeset patch # User Bram Moolenaar # Date 1662035402 -7200 # Node ID 347cf03fee2b2634fa1eb4b7646eeed24dcd0bdc # Parent 64780017de33ad945f918f4839522d86a5ec1293 patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal Commit: https://github.com/vim/vim/commit/df5320c439e9a7f7bf1ebff3cb455d45e223547a Author: K.Takata Date: Thu Sep 1 13:20:16 2022 +0100 patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal Problem: MS-Windows: cannot set cursor shape in Windows Terminal. Solution: Make cursor shape work with Windows Terminal. (Ken Takata, closes #11028, closes #6576) diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt --- a/runtime/doc/term.txt +++ b/runtime/doc/term.txt @@ -643,6 +643,18 @@ Example for an xterm, this changes the c 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* diff --git a/src/os_win32.c b/src/os_win32.c --- a/src/os_win32.c +++ b/src/os_win32.c @@ -1528,13 +1528,27 @@ decode_mouse_event( 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); + 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,6 +6784,21 @@ notsgr: } # 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,7 +7982,7 @@ vtp_sgr_bulks( if (argc == 0) { sgrfgr = sgrbgr = -1; - vtp_printf("033[m"); + vtp_printf("\033[m"); return; } diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -708,6 +708,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 347, +/**/ 346, /**/ 345,