-
Notifications
You must be signed in to change notification settings - Fork 0
fix: prevent ghost cursor on DECSCUSR style change #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # ADR 015: Client — Force repaint on DECSCUSR to prevent ghost cursor | ||
|
|
||
| **SPEC:** [client](../specs/client.md) | ||
| **Status:** Accepted | ||
| **Date:** 2026-03-26 | ||
| **Supersedes:** Partially extends [ADR 013](013.client.cursor-style.md) | ||
|
|
||
| --- | ||
|
|
||
| ## Context | ||
|
|
||
| ADR 013 introduced `cursor.ts` to intercept DECSCUSR sequences and update | ||
| `term.options.cursorStyle` / `term.options.cursorBlink` via ghostty-web's | ||
| options Proxy. The approach was sound, but it addressed only the "what to set" | ||
| layer. A second rendering gap remained, causing cursor shape changes to be | ||
| visually invisible in practice. | ||
|
|
||
| ### The ghost cursor problem | ||
|
|
||
| ghostty-web's `CanvasRenderer.render()` only **clears the cursor row** (erases | ||
| the old cursor shape from canvas) under two conditions: | ||
|
|
||
| ```js | ||
| // ghostty-web/dist/ghostty-web.js — CanvasRenderer.render() | ||
| const s = cursor.x !== lastPos.x || cursor.y !== lastPos.y; | ||
| if (s || this.cursorBlink) { | ||
| renderLine(cursor_row); // ← erases old cursor shape | ||
| } | ||
| // always runs after: | ||
| renderCursor(cursor.x, cursor.y); // ← draws new cursor shape | ||
| ``` | ||
|
|
||
| When vim switches normal → insert mode (steady block `\x1b[2 q` → steady bar | ||
| `\x1b[6 q`), neither condition is true: | ||
|
|
||
| - **Cursor did not move** — pressing `i` leaves the cursor in place (`s = false`) | ||
| - **`cursorBlink = false`** — both normal and insert use steady cursors | ||
|
|
||
| Result: the old block cursor background stays on canvas and the new bar cursor | ||
| is drawn on top of it, leaving the cursor visually unchanged. | ||
|
|
||
| ### Why ADR 013 manual verification passed | ||
|
|
||
| When vim first opens it performs a full-screen redraw, writing to every row | ||
| including the cursor row. The dirty-row paint path also calls | ||
| `renderLine(cursor_row)`, which clears and redraws the cursor correctly via | ||
| `renderCursor()`. The first mode switch on vim open therefore works fine. | ||
|
|
||
| The failure only surfaces on **subsequent in-place mode switches** (pressing `i` | ||
| or `Esc` without moving the cursor), where only the status line is updated and | ||
| the cursor row stays clean. This scenario was not covered by the original manual | ||
| verification. | ||
|
|
||
| --- | ||
|
|
||
| ## Decision | ||
|
|
||
| After detecting a cursor style or blink change, call | ||
| `term.renderer.render(term.wasmTerm, true, term.viewportY)` synchronously. | ||
|
|
||
| `forceAll = true` bypasses the dirty-state and blink checks, repainting every | ||
| row. This clears the stale cursor shape from the cursor row before | ||
| `renderCursor()` draws the new shape at the end of the same render pass. | ||
|
|
||
| `term.renderer` and `term.wasmTerm` are public properties on `Terminal` | ||
| (declared without `private` in ghostty-web's `.d.ts`). `GhosttyTerminal` | ||
| satisfies both `IRenderable` and `IScrollbackProvider` structurally, so no | ||
| casting is needed. | ||
|
|
||
| The force repaint is guarded by a `changed` flag and only fires when style or | ||
| blink actually differs from the current value — i.e., on vim mode switches, | ||
| which are infrequent. There is no per-message overhead. | ||
|
|
||
| --- | ||
|
|
||
| ## Considered Options | ||
|
|
||
| **Option A: `requestAnimationFrame` toggle on `cursorBlink`** | ||
|
|
||
| Temporarily set `cursorBlink = true` for one RAF frame so the render loop's | ||
| `if (cursorBlink)` branch clears the cursor row, then restore the correct value | ||
| via RAF callback. Correct but adds async complexity and a one-frame blink pulse. | ||
|
|
||
| **Option B: Ignore `cursorBlink` updates entirely** | ||
|
|
||
| Only update `cursorStyle` from DECSCUSR; leave `cursorBlink` controlled by | ||
| config. With the default `cursorStyleBlink: true`, blinking ensures the cursor | ||
| row is always cleared. Fragile: silently breaks for users who disable blinking | ||
| in config. | ||
|
|
||
| **Option C: Force repaint via `term.renderer.render(forceAll=true)` (chosen)** | ||
|
|
||
| Synchronous, no async, no side effects on blink state, works regardless of | ||
| config. The extra full-canvas render fires only on mode switches and costs ~1 ms | ||
| on modern hardware. | ||
|
|
||
| --- | ||
|
|
||
| ## Consequences | ||
|
|
||
| - vim, neovim, fish — cursor shape changes are immediately visible on all mode | ||
| switches regardless of blink config or cursor position. | ||
| - One additional full canvas render per DECSCUSR style change. No per-message | ||
| cost; normal typing is unaffected. | ||
| - If ghostty-web adds a public `refresh()` or `invalidateCursorRow()` API, the | ||
| `forceAll` call can be replaced with the narrower method and this ADR updated. | ||
| - When ghostty-web implements DECSCUSR natively (reading `cursor_visual_style` | ||
| from the WASM render state — see ADR 013's upstream fix checklist), the entire | ||
| `cursor.ts` module and this workaround are removed together. | ||
|
|
||
| ## Related Decisions | ||
|
|
||
| - [ADR 013 — DECSCUSR cursor style via PTY intercept](013.client.cursor-style.md): | ||
| introduced `cursor.ts`; this ADR closes the rendering gap it left open. | ||
| - [ADR 010 — Client UX polish](010.client.ux-polish.md): established the | ||
| WebSocket message handling that the intercept hooks into. | ||
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.