[PR #2829] Render the cursor state to VT #25105

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

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

State: closed
Merged: Yes


Summary of the Pull Request

Render the visibility state of the cursor to the attached terminal, via the VT renderer.

PR Checklist

Detailed Description of the Pull Request / Additional comments

The trick here is that PaintCursor is only ever called when the cursor is visible, and in PaintCursor, isOn will be on if the cursor is blinked on, and false if the cursor is blinked off. So we need to assume each frame that the cursor is not visible, and update our frame-by-frame tracker only when PaintCursor is called.

Validation Steps Performed

Used the following python script (on windows):

import os
import sys
import time # time.sleep is in seconds

# Turns VT output support on
def enable_vt_support():
    if os.name == 'nt':
        import ctypes
        hOut = ctypes.windll.kernel32.GetStdHandle(-11)
        out_modes = ctypes.c_uint32()
        ENABLE_VT_PROCESSING = ctypes.c_uint32(0x0004)
        # ctypes.addressof()
        ctypes.windll.kernel32.GetConsoleMode(hOut, ctypes.byref(out_modes))
        out_modes = ctypes.c_uint32(out_modes.value | 0x0004)
        ctypes.windll.kernel32.SetConsoleMode(hOut, out_modes)


enable_vt_support()

sys.stdout.write('\x1b[?25h[ Yo ]')
sys.stdout.flush()
time.sleep(1)

sys.stdout.write('\x1b[?25l[Peace out]')

sys.stdout.flush()
time.sleep(1)

I probably should add tests, I'm just putting this out there before I head out for the weekend.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/2829 **State:** closed **Merged:** Yes --- <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Render the visibility state of the cursor to the attached terminal, via the VT renderer. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #1127 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments The trick here is that `PaintCursor` is only ever called when the cursor is visible, and in `PaintCursor`, `isOn` will be on if the cursor is blinked on, and false if the cursor is blinked off. So we need to assume each frame that the cursor is not visible, and update our frame-by-frame tracker only when `PaintCursor` is called. ## Validation Steps Performed Used the following python script (on windows): <details> ```python import os import sys import time # time.sleep is in seconds # Turns VT output support on def enable_vt_support(): if os.name == 'nt': import ctypes hOut = ctypes.windll.kernel32.GetStdHandle(-11) out_modes = ctypes.c_uint32() ENABLE_VT_PROCESSING = ctypes.c_uint32(0x0004) # ctypes.addressof() ctypes.windll.kernel32.GetConsoleMode(hOut, ctypes.byref(out_modes)) out_modes = ctypes.c_uint32(out_modes.value | 0x0004) ctypes.windll.kernel32.SetConsoleMode(hOut, out_modes) enable_vt_support() sys.stdout.write('\x1b[?25h[ Yo ]') sys.stdout.flush() time.sleep(1) sys.stdout.write('\x1b[?25l[Peace out]') sys.stdout.flush() time.sleep(1) ``` </details> I probably should add tests, I'm just putting this out there before I head out for the weekend.
claunia added the pull-request label 2026-01-31 09:07:17 +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#25105