Conversation
The escape sequence is:
ESC[N q
N is between 0 and 6.
|
What is the context of this? |
|
Please see the link: Many modern terminals (including Windows Terminal, mintty, etc.) support changing the cursor shape dynamically — and this pairs beautifully with Emacs Evil mode, so you can visually distinguish between Normal and Insert modes (like in Vim). |
|
Is there any more authoritative documentation of these escape sequences? |
|
What about this: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html Search 'CSI Ps SP q' in the page: |
|
We have long standing PRs and issues for this feature. |
src/terminal/terminalfunctions.cc
Outdated
| /* cursor shape */ | ||
| static void CSI_cursorshape( Framebuffer* fb, Dispatcher* dispatch ) | ||
| { | ||
| int shape = dispatch->getparam( 0, -1 ); |
There was a problem hiding this comment.
I'm looking at the impl for Dispather::getparam and it looks like doesn't support returning values less than 1. But 0 is a valid cursor shape.
There was a problem hiding this comment.
Thanks. The defaultval should be 0.
Seems this commit already implements it. But the title is somewhat misleading... |
|
Something's still not quite right when the terminal is reset. Try this: printf '\x1b[6 q\x1bc' |
Do you mean it also needs to reset the cursor shape after a terminal reset? |
|
You're right that Windows Terminal doesn't reset the cursor shape after reset. But I tested xterm, gnome-terminal, alacritty, and ghostty, and they all reset cursor shape after reset. So I think we should too. |
|
I have tried this in both mintty, xterm, gnome-terminal and alacritty (in WSL though). So it seems that this behavior depends on the terminal itself? Which terminal do you see different behavior with mosh? I can have a try with it. |
|
mosh claims to be xterm and therefore should act like xterm. |
|
@dabeibao I'm not seeing that. Here's a more detailed screenshot showing my test (using commit 4ead896) Running
But then running
But when I do the above steps in a non-mosh terminal, the cursor resets back to a blinking block cursor (the default) |
|
The problem seems to be that the cursor shape is initialized to if ( f.ds.cursor_shape != frame.last_frame.ds.cursor_shape && f.ds.cursor_shape != -1 ) {
snprintf(tmp, sizeof(tmp), "\033[%d q", f.ds.cursor_shape);
frame.append(tmp);
}I think I would just get rid of the init to -1 and init to 0 instead |
Yes, thanks for finding this. I tried to initialize In xterm, the default cursor_shape is 'steady block'. And without mosh, after reset it is still 'steady block'. |
|
I tried to investigate further. Seems the problem is in the reset ( #if OPT_BLINK_CURS
screen->cursor_blink_esc = 0;
SetCursorBlink(xw, screen->cursor_blink_i);
TRACE(("cursor_shape:%d blinks:%d\n",
screen->cursor_shape,
screen->cursor_blink));
#endif
However, it appears that mosh consumes the reset seq and doesn't forward it to the terminal. Another issue with xterm (so as gnome-terminal) is, the initial cursor shape is configurable. User can set both the shape and blink state. Thus mosh cannot assume the initial cursor_shape value. So from my perspective, we may have the approaches:
I personally prefer option 1 as it will not impact the users who don't need this sequence. |
|
Ok, I think I probably also lean towards approach 1. It does seem the safest and we can always tweak this later after more experience with this change. |




The escape sequence is:
ESC[N q
N is between 0 and 6.