[PR #5251] Prevent the cursor type being reset when changing the visibility #26213

Open
opened 2026-01-31 09:14:39 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/5251

State: closed
Merged: Yes


A side effect of the SetConsoleCursorInfo API is that it resets the
cursor type to Legacy. This makes it impossible to change the cursor
visibility via the console APIs without also resetting the user's
preferred cursor type. This PR attempts to fix that limitation, by only
resetting the cursor type if the size has also been changed.

PR Checklist

Detailed Description of the Pull Request / Additional comments

I suspect the reason for the original behaviour was because the
SetConsoleCursorInfo API sets both the visibility and the size, and if
you're setting the size, it's assumed you'd want the Legacy cursor
type, because that's the only style for which the size is applicable.

So my solution was to only reset the cursor type if the requested cursor
size was actually different from the current size. That should be
reasonably backwards compatible with most size-changing code, but also
allow for changing the visibility without resetting the cursor type.

Validation Steps Performed

I've tested the example code from issue #4124, and confirmed that it now
works correctly without resetting the cursor type.

I've also tested the console's mark mode, which temporarily changes
the cursor size while selecting. I've confirmed that the size still
changes, and that the original cursor type is restored afterwards.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/5251 **State:** closed **Merged:** Yes --- A side effect of the `SetConsoleCursorInfo` API is that it resets the cursor type to _Legacy_. This makes it impossible to change the cursor visibility via the console APIs without also resetting the user's preferred cursor type. This PR attempts to fix that limitation, by only resetting the cursor type if the size has also been changed. ## PR Checklist * [x] Closes #4124 * [x] CLA signed * [ ] Tests added/passed * [ ] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I suspect the reason for the original behaviour was because the `SetConsoleCursorInfo` API sets both the visibility and the size, and if you're setting the size, it's assumed you'd want the _Legacy_ cursor type, because that's the only style for which the size is applicable. So my solution was to only reset the cursor type if the requested cursor size was actually different from the current size. That should be reasonably backwards compatible with most size-changing code, but also allow for changing the visibility without resetting the cursor type. ## Validation Steps Performed I've tested the example code from issue #4124, and confirmed that it now works correctly without resetting the cursor type. I've also tested the console's _mark mode_, which temporarily changes the cursor size while selecting. I've confirmed that the size still changes, and that the original cursor type is restored afterwards.
claunia added the pull-request label 2026-01-31 09:14:39 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26213