Skip to content

fix(terminal): blink the DOM block cursor to each cell's own colours so coloured prompt lines keep their background - #50986

Merged
nwparker merged 1 commit into
stablyai:mainfrom
mmarabel:mmarabel/cursor-blink-cell-bg
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
mmarabel:mmarabel/cursor-blink-cell-bg

Conversation

@mmarabel

@mmarabel mmarabel commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

With GPU rendering off (or when Orca falls back to the DOM renderer), the blinking block cursor punched a hole in coloured lines. On its "off" blink it showed the plain terminal background instead of the line's colour, so coloured prompt bands (agent TUIs, powerline prompts) flickered with a dark square. After about 5 idle minutes, when the cursor stops blinking, it could vanish completely on those coloured cells. Now the off blink shows whatever is really underneath the cursor, and a cursor that is not blinking always stays visible.

What Changed

Before (DOM renderer, block cursor on a cell with its own background):

  • Blink off phase: the cell lost its background (transparent row background showed through) and its glyph was drawn in the cursor colour.
  • Not blinking (blink idle after 5 minutes, rows without xterm-focus): on truecolor and selected cells the cell's inline background won over the cursor colour, so the cursor was invisible.

After:

  • Blink off phase: the cell shows its own background and text colours (truecolor, palette and selection alike).
  • Blink on phase and every non-animating state: a solid cursor in the cursor colours. Default cells look the same as before.

Mechanism:

  1. xterm source patch, DomRenderer._injectCss (config/patches/xterm-src/@[email protected]): the block blink keyframe now holds the cursor colours for 0%, 50% and drops the 50% { background-color: inherit } step. The animation uses step-start, so the second half jumps to the implicit 100% keyframe, which is the cell's own computed style (Orca's inline truecolor background or the xterm-bg-N class).
  2. The plain (non-!important) block cursor rule is removed. The existing !important rule now covers every block cursor that is not animating: blink off, rows without xterm-focus, and blink idle. It is not applied to the animating cursor because !important would beat the animation.
  3. terminal-dom-block-fill.ts: a block cursor sitting on a U+2580–U+2595 block glyph keeps the seam-free gradient fill, but painted in currentColor and without forcing inline color: transparent. The fill now follows the cursor's animated colour, so a cursor on █ still blinks and stays solid when it stops. Already-filled cursor spans take the early return, and cursor spans skip the getComputedStyle read.
  4. The minified @xterm/xterm patch and its lockfile hash are regenerated output of regenerate-xterm-patches.mjs --write (a token diff of the built xterm.js/xterm.mjs shows only these CSS strings).

Why

The bad keyframe and the non-!important base rule are upstream xterm.js code (unchanged on xterm.js master). Orca already patches the DOM row factory to write truecolor backgrounds as inline styles, so the fix belongs in the same patch. Alternatives considered: revert/revert-layer keyframe values or a per-cell CSS variable need more moving parts and would make the row factory resolve every cell colour; the implicit 100% keyframe already gives the exact cell colours. Keeping the plain block rule alongside the new keyframe would make it the underlying value, leaving palette cells cursor-coloured in the off phase.

Linked Issue

Fixes #50985

Visual Proof

Headless Chrome with xterm 6.1.0-beta.336 (DOM renderer), main's patch vs this branch's patch. Line abcXYZ with a truecolor background band, cursor on X. Blink phases are frozen with the Web Animations API; the idle case adds the xterm-cursor-blink-idle class xterm sets after 5 minutes.

State Before (main) After (this PR)
Truecolor cell, blink off phase before truecolor off after truecolor off
Truecolor cell, blink idle before idle truecolor after idle truecolor
Palette background cell, blink off phase before palette off after palette off
Selected truecolor cell, blink off phase before selected off after selected off
Red █ on truecolor, blink on / off (after) after block glyph on after block glyph off

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • Reproduced on macOS (m4air) in headless Chrome over CDP with the DOM renderer, loading the npm @xterm/[email protected] tarball with main's patch and with this branch's patch. For truecolor, palette, selected, truecolor-foreground and default cells × blink on, blink off, blink idle, unfocused rows and cursorBlink=false, read the cursor's computed background-color/color. Main: off phase transparent on every coloured cell; idle and unfocused rows invisible on truecolor and selected cells. Branch: off phase keeps each cell's colours (e.g. rgb(48, 48, 48) band, rgb(52, 101, 164) palette blue); every other state is a solid cursor.

  • Cursor on a red █ with an 80px line height, live animation sampled 2px from the cell top (outside the font glyph): blinking alternates accent/cell colour, static stays solid accent, matching main's static fill with no cursor-coloured strips.

  • New terminal-dom-block-fill.test.ts (happy-dom): the block cursor span keeps its inline colour, gets the currentColor fill and is idempotent across passes. Fails on main (expected 'transparent' to be 'rgb(255, 0, 0)'), passes here.

  • Targeted vitest: terminal-rendering/ plus the xterm smoke tests terminal-capability-replies and terminal-restore-sgr-latch (97 passed). regenerate-xterm-patches.mjs --check passes (all 5 packages in sync, including the lockfile hash). oxlint, oxfmt, anti-slop, ast-grep and the changed-code quality gate are clean.

  • The change is renderer CSS plus a renderer DOM helper, identical on macOS, Linux and Windows; not run in a packaged Windows/Linux build.

Performance: the CSS runs once per theme change in _injectCss, not per cell. Blink idle over 10 s of real blinking: RecalcStyleCount 610/607 (main) vs 605/608, RecalcStyleDuration 26–37 ms vs 28–31 ms, no layout either way. Stream render of 3000 lines × 150 truecolor/palette SGR cells at 160×50: 1834/1632/1453 ms vs 1465/1435/1456 ms. fillBlockSpan (DOM row render path) only does extra work for the single cursor span on a block glyph, and that span now skips main's getComputedStyle; happy-dom passes are within noise (81-span row, median repass 0.043/0.026 ms vs 0.022/0.018 ms). Each terminal injects and fills its own rows with no shared state, so per-update cost at N=200 panes is unchanged.

Risk

Level: Low

Only the DOM renderer's block cursor changes; bar, underline and outline cursors and the WebGL renderer are untouched. The riskiest part is the !important rule for non-animating block cursors: on a selected or decorated cell the cursor now draws over the selection colour (as cursorBlink=false already did upstream), and in the off phase a selected cell shows the selection colour instead of transparent. The off-phase glyph now uses the cell's own foreground, matching the WebGL renderer. Back out with a plain revert (the xterm patch and lockfile hash revert together).

Review

  • Cross-platform: CSS and a renderer DOM helper only, no platform branches.
  • SSH and remote: rendering happens in the desktop renderer, so remote panes behave the same; no protocol change.
  • Agents: none affected beyond agent TUIs that paint coloured input lines now rendering correctly.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

The same keyframe bug exists in xterm.js master and can be reported upstream separately.

Original fix by @mmarabel in #50986

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The DOM fill logic now uses currentColor for block-cursor fills and preserves the cursor’s text color. A new test checks cursor color, fill foreground, and background image after repeated calls to applyDomBlockFills. The xterm CSS patch updates block-cursor blink keyframes and timing. It also applies important cursor-color rules to non-blinking cursors, cursors in unfocused rows, and cursors in idle-blink rows.

Severity of issue fixed: Medium

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Out of Scope Changes check Inconclusive The xterm patch, its regenerated hash, and the addon patches are tied to the DOM renderer block-cursor CSS in #50985, so they are in scope. The head diff (merge base 72810b9 to head 374eee6) also ch… Explain in the PR description how terminal-dom-block-fill.ts changes support #50985, and correct the statement that no automated test was added. If the change is not needed for the issue, remove it from this PR.
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: the DOM block cursor now blinks using each cell's own colours, so coloured prompt lines keep their background. It matches the patch (keyframe, step-start, !important r…
Description check Passed The description follows the repository template. It has ELI5, What Changed (before and after, plus mechanism), Why (with alternatives), Linked Issue (Fixes #50985), Visual Proof (an image link), Testi…
Linked Issues check Passed Linked issue #50985 is the only active direct target. Its requirements are coding requirements: (1) in the blink-off phase, a block cursor on a coloured cell shows that cell's own background and text …
Full details: Title check

Explanation

The title names the main change: the DOM block cursor now blinks using each cell's own colours, so coloured prompt lines keep their background. It matches the patch (keyframe, step-start, !important rule) and the new terminal-dom-block-fill changes. It is specific and follows the fix(terminal) convention. It is long (115 characters), but the content is accurate.

Full details: Description check

Explanation

The description follows the repository template. It has ELI5, What Changed (before and after, plus mechanism), Why (with alternatives), Linked Issue (Fixes #50985), Visual Proof (an image link), Testing with a detailed manual headless Chrome check, Performance with a reason, Risk with level and backout, AI Disclosure, Review, and Checklist. The Visual Proof image is a placeholder-like link, and the test-anti-pattern box and the lint/typecheck/test/build checklist item are unchecked. Those gaps are minor and do not make the description incomplete.

Full details: Linked Issues check

Explanation

Linked issue #50985 is the only active direct target. Its requirements are coding requirements: (1) in the blink-off phase, a block cursor on a coloured cell shows that cell's own background and text colour; (2) after blink idle, the block cursor stays visible on truecolor cells. The patch change in config/patches/xterm-src/@[email protected] (DomRenderer.ts _injectCss) keeps only the on-phase keyframe (0%, 50% with cursor colours), so the off phase reaches the implicit 100% keyframe, which is the cell's computed style. It uses step-start for the block animation. It replaces the non-!important block cursor rule with an !important rule covering blink off, unfocused rows, and blink idle. The previous conclusion still holds, because the patch hunk was not changed since the previous review. Verification is author-reported (headless Chrome computed-style check). The issue does not require an automated test. The lockfile hash in pnpm-lock.yaml is an ignored file; its contents were not inspected. The newly changed src/renderer/src/lib/pane-manager/terminal-rendering/terminal-dom-block-fill.ts also affects block-cursor spans, but this assessment does not establish how it interacts with the off-phase result; the patch-level evidence above is unchanged.

Full details: Out of Scope Changes check

Explanation

The xterm patch, its regenerated hash, and the addon patches are tied to the DOM renderer block-cursor CSS in #50985, so they are in scope. The head diff (merge base 72810b9 to head 374eee6) also changes src/renderer/src/lib/pane-manager/terminal-rendering/terminal-dom-block-fill.ts (+14/-5). In block-cursor spans, it uses currentColor for the fill, keeps the cursor's span colour instead of setting it to transparent, and adds terminal-dom-block-fill.test.ts (+23). This is in the DOM renderer block-cursor area, so it is not shown to be unrelated. However, the PR description does not mention this file. Its Mechanism section lists only the patch hunk. The description also says no automated test was added, but a test file exists. The link between this file and #50985 is not explained.

Resolution

Explain in the PR description how terminal-dom-block-fill.ts changes support #50985, and correct the statement that no automated test was added. If the change is not needed for the issue, remove it from this PR.

  • 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

Recent 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: 1bb83b3e-82f5-438d-8051-7309289cd5e4
Commits

Reviewing files that changed from the base of the PR and between 4fa1242 and 374eee6.

Files selected for processing: 2

  • src/renderer/src/lib/pane-manager/terminal-rendering/terminal-dom-block-fill.test.ts
  • src/renderer/src/lib/pane-manager/terminal-rendering/terminal-dom-block-fill.ts

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

…so coloured prompt lines keep their background

In the DOM renderer the block cursor's blink-off keyframe set
`background-color: inherit`, which took the transparent row background
and punched a hole into coloured prompt bands. The non-blinking block
cursor rule was not `!important`, so inline truecolor and selection
backgrounds hid the cursor once blinking went idle or rows lost focus.

The xterm source patch now holds the cursor colours for `0%, 50%` with
`step-start`, so the off half falls back to the cell's own colours, and
one `!important` rule covers every non-animating block cursor (blink
off, unfocused rows, blink idle). The block-element fill keeps block
cursor spans drawn in currentColor so a cursor on a block glyph still
blinks and stays solid when it stops.

Fixes stablyai#50985

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the mmarabel/cursor-blink-cell-bg branch from 4fa1242 to 374eee6 Compare November 27, 2026 17:26
@nwparker
nwparker merged commit 38aa5a7 into stablyai:main Nov 27, 2026
68 checks passed
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.

[Bug]: Blinking block cursor shows the terminal background instead of the cell's colour (DOM renderer)

2 participants