Skip to content

fix(terminal): draw the hardware cursor in remounted panes before first focus - #41736

Merged
nwparker merged 2 commits into
mainfrom
nwparker/agy-cursor
Nov 13, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/agy-cursor

Conversation

@nwparker

@nwparker nwparker commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

The terminal library waits for a "you got focus" signal before it ever draws the cursor. When Orca rebuilds a terminal (reload, reattach), focus never "arrives" because it never left, so the signal doesn't fire. agy uses the real terminal cursor, so its cursor goes missing until you press a key. This tells the terminal to draw the cursor right away and only hide it when the app asks.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7

What Changed

  • buildDefaultTerminalOptions() now sets xterm's init-only showCursorImmediately: true. Pane xterms, dashboard previews and the settings preview all use these defaults.
  • The return type is widened to ITerminalOptions & ITerminalInitOnlyOptions, and createPaneDOM is updated to match.
  • Added a regression test: a fresh xterm (as after a remount) fed agy's inline frame now has a drawable cursor without focus or input. A second test pins xterm's default behaviour, and a third checks that ?25l still hides the cursor.

Before: after a pane is rebuilt, agy shows no cursor (not even the hollow unfocused outline) until the first keypress, even though agy sent ?25h and xterm reports isCursorHidden=false.
After: the cursor follows ?25h/?25l immediately.

Why

xterm only sets coreService.isCursorInitialized in three cases: on a textarea focus event, on a keydown/keypress, or when switching to or from the alternate screen (DECSET/DECRST 1049). The WebGL and DOM renderers skip drawing the cursor while that flag is false. Repro in a dev build: run agy, reload the renderer, and the pane reports isCursorInitialized=false, isCursorHidden=false with the textarea already focused. No cursor appears in five shots spread across the blink cycle, and one keystroke brings it back.

Other agents mostly hide this: Claude Code, Codex and cursor-agent hide the hardware cursor and draw their own, and alt-screen TUIs flip the flag as a side effect. agy draws inline and, in DEC 2026 mode, sends ?25h once and never repeats it, so nothing else re-initializes the cursor.

This is the same root cause and the same fix as the mobile change in #11387. The alternative was re-firing _showCursor from Orca's remount and focus paths, but that means patching each path where focus is kept, and it relies on private xterm API.

Linked Issue

N/A (maintainer; no existing issue for desktop). Related: #11387 (same root cause on mobile), #14632 / #14638 (DECTCEM restore on reattach for "hide/show once" TUIs).

Visual Proof

N/A for an after-capture. The before state was reproduced in a dev Orca over CDP: after a renderer reload, the cursor cell had 0 cursor pixels across 5 shots, and one keystroke brought it back. The after state is covered by the regression test, not by a screen capture.

Testing

  • I manually tested these changes locally (reproduced the bug on macOS; the after state is not yet checked on screen)
  • Automated tests added/updated (pane-terminal-cursor-initialization.test.ts)
  • Every added test fails without this change (the first case fails with showCursorImmediately: false)

Also ran pnpm typecheck and the pane-manager, dashboard-popout and settings/terminal suites: 26 files, 58 tests passing.

Risk

Level: Low

A brand-new terminal now shows its cursor before the first focus or keystroke. This is standard behaviour in other terminals. A shell pane that was never focused will show the unfocused outline cursor instead of nothing. Apps that hide the cursor (?25l) are unaffected. Renderer-only and cross-platform, with no impact on saved data, SSH or mobile. To back it out, a plain revert is enough.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I stated the risk

…st focus

xterm withholds the cursor until its textarea gets a focus event or a
keystroke. A remounted pane (reload, reattach) keeps DOM focus, so no
event fires and TUIs that use the hardware cursor, like agy, show no
cursor until the next keypress. Set showCursorImmediately so DECTCEM
alone decides visibility, matching the mobile fix in #11387.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

Default pane terminal options now set showCursorImmediately to true and include the initialization-only options type. Pane DOM creation types merged terminal options with the same intersection. A new test checks cursor initialization and visibility after a fresh terminal processes an inline-agent frame.

Merge Risk: Minimal · up to 1474c

This change makes the terminal cursor appear immediately after a pane is rebuilt, and nothing found blocks merging. The remaining feedback only suggests stronger test coverage.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the terminal cursor is drawn in remounted panes before first focus. It matches the changeset, which sets showCursorImmediately to true in the default xterm options and…
Description check Passed The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue (N/A with related issues cited), Visual Proof (N/A with reason and a reproduction note), Testing with checkbo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the terminal cursor is drawn in remounted panes before first focus. It matches the changeset, which sets showCursorImmediately to true in the default xterm options and widens the return type. The title is a conventional fix(terminal) commit subject and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue (N/A with related issues cited), Visual Proof (N/A with reason and a reproduction note), Testing with checkboxes, Risk with level Low and a revert path, and a Checklist. The Review, Notes, and AI Disclosure sections are absent or not filled in. The Agent skill boundary section is marked. The Linked Issue section does not contain a 'Fixes #' link, which the template says should always exist for outside contributors. The author states they are a maintainer, so this is acceptable. The Visual Proof section gives a reproduction note but no before/after capture. The template asks for one for UI or behavior changes, and the author explains why it is not provided.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick comments: 1

src/renderer/src/lib/pane-manager/pane-terminal-cursor-initialization.test.ts: 1

34-37: Trivial · Maintainability & Code Quality · Heavy lift

Add coverage for the rendered cursor.

This assertion checks private flags on a terminal that the test never opens. It can pass even if the renderer does not draw the cursor before focus or input.

Add a browser-level test that opens the terminal, writes the frame without focus or input, and checks the rendered cursor. Also check that ?25l hides it.

Based on learnings, tests should assert observable outputs rather than private state.

Source: Learnings

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c4043585-6b52-416d-9951-61be1ca59e51
Commits

Reviewing files that changed from the base of the PR and between 9ac4894 and 1474c44.

Files selected for processing: 1

  • src/renderer/src/lib/pane-manager/pane-terminal-cursor-initialization.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@nwparker
nwparker merged commit a17de5c into main Nov 13, 2026
48 checks passed
@nwparker
nwparker deleted the nwparker/agy-cursor branch November 13, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant