-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider supporting [extension to VT,] DECSCUSR "0" to restore cursor to user default to help vim/others #1604
Comments
I'm not sure what escape sequences Windows Terminal supports for changing the cursor shape, nor what (Neo)Vim outputs, so sorry if I get it wrong. I assume that the DECSCUSR escape sequence is being used (see e.g. at ctlseqs.html). In gnome-terminal (vte) we intentionally deviate from the xterm's behavior (the behavior documented on the linked page). For parameters 1–6 we go with the given mode. However, if the parameter is 0 (or missing), we revert to whichever cursor shape the user specified as their favorite in the terminal's preferences. This might be a behavior for WIndows Terminal to consider, too. |
This is actually intended behavior for Vim/Nvim and I can't recall any sort of "restore cursor leaving application mode" termcap that could be implemented in the terminal. And yes, that's correct... DECSCUSR has been implemented in WindowsTerminal for changing cursor shape (1-6). Vim explicitly changes the cursor shape for each of it's editing modes and it requires that you assign the ESC sequences in your vimrc file, as they are not using any sort of standard termcap variable for this. Vim does not change the cursor shape on exit. The cursor shape from normal mode will remain, since you must exit from normal mode. For more info in Vim: It's easy to change the cursor shape upon exit for yourself using an I hope that helps! |
@xtremeperf Thanks for your tip! |
The DECSCUSR sequence is a poorly designed one. One problem is the lack of save/restore or revert, which we somewhat address in gnome-terminal by deviating from the standard. This way vim could restore the user's preferred version on exit. The other problem is that two orthogonal properties are tied together. For an app like vim, it really makes sense to toggle between two different shapes, while leave blinking at the user's preferred setting. It's currently not possible. The best solution could be to cooperate between terminal emulators and apps to come up with a better designed escape sequence. Until then, we live with the limitations, and optionally come up with hacks to mitigate the problems. |
I like the idea of using a nonstandard |
I'll float that to @zadjii-msft -- if we don't want to do it, we'll close this issue as "unfortunately by design". 😄 |
I looked into this a little more. The main reason the cursor doesn't get reset when returning to the shell is because neovim doesn't enter alternate screen mode upon startup... therefore it doesn't return from any sort of alternate screen mode upon exit. Here's how it's done in Vim using xterm sequences (as in DECRC) |
I don't get it, what's the connection between cursor shape and alternate screen? At least in xterm and gnome-terminal it's the same shape for both screens, not one per screen. Is it different in Windows Terminal? |
There are some XTERM-specific capabilities for an Alternate Screen Buffer and Save/Reset Cursor, among others. The intent is provide a picture of the full-screen application's display on the scrollback, but without wiping out the text that would be shown before the application was initialized. The display and cursor properties are saved and then the terminal switches to an alternate buffer with it's own properties. When done, the initial display, along with it's cursor, are restored. DEC Private Mode Set (DECSET) --- CSI ? P m h P s = 1 0 4 7 --- Use Alternate Screen Buffer I haven't tested these sequences while using various different combinations of cursor shape between each screen buffer specifically, but after running vim and changing the normal cursor to a solid line, the original underscore cursor shape, blink, position, etc. was restore upon exiting the alt. screen buffer mode. |
In Xterm and VTE, the same cursor shape+blinking is shared across the normal and alternate screen. Also, saving/restoring the cursor does not save/restore its shape+blinking. That is, it looks to me that the following three are independent:
and there just happens to be an escape sequence which sets 1. and 2. at the same time.
It could be that Windows Terminal differs from Xterm and VTE here. |
Also note that showing/hiding the cursor (DECTCEM) seems to be an exempt from saving/restoring or alternate screen switching. So in bullet point 2 above, "cursor" stands for the logical concept, "active data/presentation position" as ECMA-48's calls it; whereas in bullet point 3 "cursor" refers to its graphical representation. (ECMA-48: "In general, the active presentation position is indicated in a display by a cursor.") ctlseqs.html doesn't have this clear distinction, it uses the word "cursor" for both concepts, just as probably most people do. |
To add my 2c: Looking at the spec for DECSCUSR, it seems like
I'm definitely okay with having |
I should also mention that there is already a DEC standard for querying (and thus being able to restore) the user's cursor settings - the |
@xtremeperf I have... In xterm, DECSET 1049 seems to behave as documented, i.e. the effects on the cursor are the same as for DECSC, which doesn't save the cursor style. Requesting the current state with DECRQSS might work, but it's subject to all the usual problems -- request/response latency, lack of widespread support, etc. |
I know of a number of terminal emulators that support As for latency, that's surely not an issue for something like an editor (which was the original use case for this issue) . You fire off the request sequence at startup and then just carry as normal. If you receive a response at some point before shutting down, then you've got what you need to restore the cursor. If not, it's hardly the end of the world. |
Yeah, that's how I envisioned doing it for this particular issue too, although the latency can be annoying for other uses of |
I'm supportive of the proposal to repurpose 0 to restore the user's default in iTerm2, which came to my attention here: https://gitlab.com/gnachman/iterm2/-/issues/8769 I'd like to see one or two more terminals commit to this before making the change, though. I'm sure it will break some users' configurations, and it's only justifiable if it's the clear path forward. |
@gnachman I've done a bit of testing on the terminals I have installed, and there are actually a few that support this extension. Other than VTE, there's also mintty and alacritty, which support both 0 and a missing parameter for selecting the user's preferred cursor. Then there is kitty (the Linux terminal, not the putty fork) which supports only 0 (a missing parameter selects the block cursor). I still think |
Thanks for providing the additional context, @j4james . I'm not a fan of DECRQSS for two reasons:
I think the strongest argument in favor of adopting this change is that 0 is the same as 1. Anyone who has problems can fix them without too much trouble. Considering VTTY, mintty, and alacritty already support it, that's strong evidence that there is a lot of hard-to-fix software in the wild. |
FYI I've implemented DECSCUSR 0 to reset cursor style & blink in gnachman/iTerm2@5680f97 |
This PR is about the behavior of DECSCUSR. This PR changes the meaning of DECSCUSR 0 to restore the cursor style back to user default. This differs from what VT spec says but it’s used in popular terminal emulators like iTerm2 and VTE-based ones. See #1604. Another change is that for parameter greater than 6, DECSCUSR should be ignored, instead of restoring the cursor to legacy. This PR fixes it. See #7382. Fixes #1604.
🎉This issue was addressed in #7379, which has now been successfully released as Handy links: |
The fix for this issue was just released as part of Windows in Insider Build 20236! |
Environment
Steps to reproduce
Expected behavior
After closing nvim I would expect to have the "vintage" cursor again.
Actual behavior
Cursor is a filledBox that doesn't blink anymore
The text was updated successfully, but these errors were encountered: