fix: cursor shape (DECSCUSR), Ctrl+V forwarding, and mouse scroll in alt screen#147
Open
jesse23 wants to merge 1 commit into
Open
fix: cursor shape (DECSCUSR), Ctrl+V forwarding, and mouse scroll in alt screen#147jesse23 wants to merge 1 commit into
jesse23 wants to merge 1 commit into
Conversation
Bug 1 — DECSCUSR cursor shape silently dropped: Add ghostty_render_state_get_cursor_style and ghostty_render_state_get_cursor_blinking WASM exports to the patch. GhosttyTerminal.getCursor() now reads both from the terminal state instead of hardcoding style:'block' and blinking:false. Bug 2 — Ctrl+V not forwarded to PTY: InputHandler.handleKeyDown emits the encoded \x16 byte to onDataCallback before returning, so apps that read Ctrl+V natively (e.g. image paste flows) receive it. The browser paste event still fires afterwards so handlePaste continues to cover text paste unchanged. Bug 3 — Mouse wheel sends arrow keys when mouse tracking is active: Terminal.handleWheel checks hasMouseTracking() in the isAlternateScreen branch. When active, it emits an SGR scroll sequence (\x1b[<64/65;col;rowM) via dataEmitter instead of arrow keys, matching xterm.js behaviour. The arrow-key fallback is preserved for apps without mouse tracking (less, man, etc.). Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
5 tasks
diegosouzapw
added a commit
to diegosouzapw/ghostty-web
that referenced
this pull request
May 23, 2026
…alt screen Three independent PTY-input gaps wrapped in a single port from upstream coder#147 because they share the same WASM-side patch surface. 1. **DECSCUSR (cursor shape)** — apps that send the `CSI Ps SP q` DECSCUSR sequence to change cursor shape (block/bar/underline) and blink state used to be silently ignored on the JS side. WASM now exports `render_state_get_cursor_style` and `render_state_get_cursor_blinking`; the renderer queries them each frame so vim/tmux insert-mode cursor styles take effect. 2. **Ctrl+V forwarding** — Ctrl+V used to be intercepted and dropped so the browser paste event could handle it. That broke apps that read raw \\x16 from the PTY (e.g. opencode triggering osascript image paste). Ctrl+V now emits \\x16 via the Ghostty key encoder AND still lets the paste event fire for text content. Cmd+V on macOS behaves as before (no byte emitted, paste event handles it). 3. **Mouse scroll in alt screen** — wheel events while in the alt screen buffer (vim, less, htop) used to bypass mouse-tracking. Now they go through the same mouse-tracking path as the main screen, so apps that subscribe to wheel events receive them in alt screen too. WASM-API patch updates: - New exports for cursor_style / cursor_blinking - Hunk headers in patches/ghostty-wasm-api.patch recounted to reflect the added lines (the original patch upstream had stale @@ headers that prevented `git apply` from succeeding) The two pre-existing "Ctrl+V/Cmd+V should not emit onData" tests were documenting the old (now-incorrect) behaviour and have been rewritten to assert the new contract: Ctrl+V → \\x16, Cmd+V → empty (encoder returns no bytes for Super modifier). Co-authored-by: Jesse Peng <jesse23@gmail.com> Inspired-by: coder#147
diegosouzapw
added a commit
to diegosouzapw/ghostty-web
that referenced
this pull request
May 23, 2026
…alt screen (#13) Three independent PTY-input gaps wrapped in a single port from upstream coder#147 because they share the same WASM-side patch surface. 1. **DECSCUSR (cursor shape)** — apps that send the `CSI Ps SP q` DECSCUSR sequence to change cursor shape (block/bar/underline) and blink state used to be silently ignored on the JS side. WASM now exports `render_state_get_cursor_style` and `render_state_get_cursor_blinking`; the renderer queries them each frame so vim/tmux insert-mode cursor styles take effect. 2. **Ctrl+V forwarding** — Ctrl+V used to be intercepted and dropped so the browser paste event could handle it. That broke apps that read raw \\x16 from the PTY (e.g. opencode triggering osascript image paste). Ctrl+V now emits \\x16 via the Ghostty key encoder AND still lets the paste event fire for text content. Cmd+V on macOS behaves as before (no byte emitted, paste event handles it). 3. **Mouse scroll in alt screen** — wheel events while in the alt screen buffer (vim, less, htop) used to bypass mouse-tracking. Now they go through the same mouse-tracking path as the main screen, so apps that subscribe to wheel events receive them in alt screen too. WASM-API patch updates: - New exports for cursor_style / cursor_blinking - Hunk headers in patches/ghostty-wasm-api.patch recounted to reflect the added lines (the original patch upstream had stale @@ headers that prevented `git apply` from succeeding) The two pre-existing "Ctrl+V/Cmd+V should not emit onData" tests were documenting the old (now-incorrect) behaviour and have been rewritten to assert the new contract: Ctrl+V → \\x16, Cmd+V → empty (encoder returns no bytes for Super modifier). Inspired-by: coder#147 Co-authored-by: Jesse Peng <jesse23@gmail.com>
|
Hi @jesse23! 👋 Your work on this PR inspired a commit in my fork diegosouzapw/ghostty-web. I'm working on OmniRoute, a project that provides free access to LLM models, and I'm planning to use ghostty-web as the terminal component there. Your work is part of what makes that possible. 🙏 Feel free to check it out — contributions and feedback are very welcome! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes all three issues reported in #145. Each fix is small and self-contained.
Bug 1 — DECSCUSR cursor shape silently dropped
GhosttyTerminal.getCursor()hardcodedstyle: 'block'andblinking: falsewith TODO comments. Added two new WASM exports to the patch:ghostty_render_state_get_cursor_style(term)→0=block,1=bar,2=underline (readsterminal.screens.active.cursor.cursor_style)ghostty_render_state_get_cursor_blinking(term)→ bool (readsterminal.modes.get(.cursor_blinking))getCursor()now returns the live values so the renderer reflects cursor shape changes from PTY output.Bug 2 — Ctrl+V not forwarded to PTY
handleKeyDownreturned early onCtrl+V/Cmd+Vwithout emitting\x16, so apps that read it natively (image paste flows, readlineyank) never received it. Now encodes and emits the keydown viaonDataCallbackbefore returning. The browserpasteevent still fires afterwards —handlePastecovers text paste unchanged.Bug 3 — Mouse wheel sends arrow keys when mouse tracking is active
handleWheelsent\x1B[A/\x1B[Bunconditionally on the alternate screen, ignoring whether the app had requested mouse events. Added ahasMouseTracking()guard: when active, emits an SGR scroll sequence (\x1b[<64/65;col;rowM) viadataEmitterinstead. The arrow-key fallback is preserved for apps without mouse tracking (less,man, etc.).Note: Bug 1 requires a WASM rebuild to take effect at runtime. The patch changes are ready; the resulting
.wasmand.jsbundle would need to be regenerated.Ref: #145
Downstream pR to prove the fix works:
jesse23/webtty#21