fix(web): the terminal cursor no longer leaves faint lines when it blinks off#21641

open7
main
GitHub fork: fix/11402-terminal-cursor-fringe
opened5d agobyTtiliakoos
View on GitHubTwo-way sync enabledPR last imported 2d ago

Problem

At a fractional device pixel ratio the integrated terminal's cursor leaves two faint lines at the top and bottom of its cell when it blinks off (https://git.cafe/pingdotgg/t3code/issues/11402). On a Mac that happens after View > Zoom In in the desktop app (one step gives a ratio of about 2.19) or with browser zoom on web; elsewhere at a 125% or 150% display scale. Row edges then fall partway through device pixels, so the row's background repaint only partly covers the cursor's edge pixels and blends over them instead of replacing them.

Change

renderGhosttySnapshot in apps/web/src/terminal/ghostty/renderer.ts puts each row's top and bottom on whole device pixels, using the canvas transform's scale, and draws the row's background, selection, text clip, solid Powerline separators (https://git.cafe/pingdotgg/t3code/pulls/5607) and the cursor with that snapped height. Neighbouring rows share an exact edge, so repainting a row replaces every pixel it drew. At a whole-number ratio, such as the default 2 on a Retina display, nothing moves. The mocked context in surface.test.ts gets a getTransform stub.

Scope and approval

https://git.cafe/pingdotgg/t3code/issues/11402 is a triaged bug; the triage suggests "snap row/cursor Y to the device pixel grid" with an offscreen-canvas pixel test. When closing https://git.cafe/pingdotgg/t3code/pulls/11620, @juliusmarminge invited a smaller version: "If you want to send that smaller version with an offscreen-canvas pixel test at a fractional origin, that would be welcome." This rebuilds @Lucenx9's https://git.cafe/pingdotgg/t3code/pulls/11424 (the same snapping) on current main, as its closing comment suggested, with a real-canvas test in place of the mocked one.

One correction to the triage: on main the row origin is always a whole CSS pixel (clientHeight and the cell height are integers), so the fractional edges come from the device pixel ratio. Snapping only the origin in surface.ts would leave every later row between device pixels, which is why the snap is per row and why the test uses a fractional canvas transform. Web and desktop share this renderer; the triage notes mobile's native terminal does not use it.

Verification

  • New renderer.browser.test.ts draws on a real Chromium canvas at 1.25x and 2.2x for the bar, block, underline and hollow cursors: cursor on, then off, then a count of the pixels that are not the background. On main all 8 fail, leaving 6 to 36 pixels (2.2x block: 36, an 18-pixel line at the top and the bottom of the cell); with the change all 8 pass with 0. A second case draws a separator, then repaints only its row without it: with https://git.cafe/pingdotgg/t3code/pulls/5607's unsnapped height it leaves 1 pixel below the row at both ratios, with the change 0. surface.test.ts: 28 passed. vp lint, vp fmt --check and the web typecheck are clean.

  • Real app: the dev desktop app from this branch on a fresh .t3 with a throwaway project, light theme, terminal focused at an idle prompt. I set the ratio to 2.2 over CDP (Emulation.setDeviceMetricsOverride), close to the 2.19 one Zoom In step gives, since the menu's Zoom In can't be driven from the automation. The terminal canvas region was exported every 100 ms for 3 s (exact canvas pixels, not a screen capture):

    blink-off framespixels left in the cursor cell, every off frame
    main1536 (device rows 8 and 48, 18 each)
    this branch150

    At the default ratio of 2 this branch also leaves 0 in all 14 off frames.

    Cursor off at 2.2x, before (6x, nearest neighbour):

    Before: two faint lines stay where the cursor was

    After:

    After: the cell is clear

    Blinking, before on the left and after on the right (4x):

    Blinking, before left and after right

  • Not checked: Windows or Linux at a fractional display scale (same renderer and arithmetic), and the Zoom In menu item itself. Not changed: horizontal edges, which only matter for a cursor or separator at either end of a row, where it meets the row repaint's own edge; the issue reports the top and bottom lines.

Claude Opus 5.5 via T3 Code

Fixes #11402 GitCafe: https://git.cafe/pingdotgg/t3code/issues/11402

Evidence

Maintainer captures of the real web app's integrated terminal. Before is main at 8d3b061121. After is this branch's head 2a5ca7fae5 with that main merged in locally (a1c2f1e5f3). The branch is on a fork, so that merge was not pushed: the branch still needs a merge of main (205 commits behind). Between before and after, only the three files in this PR differ.

Environment for every capture: chromium-headless-shell 148.0.7778.96 (Playwright 1.60.0), CSS viewport 1280×800, zoom 100%. The device pixel ratio is set with CDP Emulation.setDeviceMetricsOverride deviceScaleFactor, not browser zoom, so the layout is identical at every ratio. The terminal uses the default font family at 11 px (15 px rows, so row edges fall on fractional device pixels) and runs bash --norc --noprofile. Each dev server ran on its own isolated state.

The number in each row is how many pixels that differ from the background remain in the cursor cell (±1 device px) on a blink-off frame, read from the canvas right after an on→off transition. Each sheet shows the zoomed before and after cursor cell, a zero-threshold cell diff, and the whole panel before and after with a zero-threshold panel diff.

rowDPRthemecursorbeforeaftersheet
S11darkblock, off00 (whole panel identical)S1
S21.25darkblock, off110S2
S31.5darkblock, off110S3
S42darkblock, off00 (whole panel identical)S4
S52.2darkblock, off340S5
S61.25lightblock, off90S6
S72.2lightblock, off320S7
S81.25darkbar, off50S8
S92.2darkbar, off140S9
S101.25darkblock, onsolidsolidS10
S112.2darkblock, onsolidsolid, starts 1 device px lowerS11

Cursor off at 2.2, dark (S5). Before leaves lines at the top and bottom of the cell; after leaves nothing:

S5: at DPR 2.2, before leaves two lines in the cursor cell when the cursor blinks off; after the cell is clear

Recordings are about 6 s each, roughly 6 blink cycles at 500 ms on and 500 ms off, with before on the left and after on the right. They are canvas frames copied on every animation frame and upscaled nearest-neighbour. The two halves come from separate sessions, so their blink phases are up to 0.5 s apart. In each off phase at 1.25 and 1.5, the left half keeps a one-device-pixel line at the bottom of the cell; at 2.2 it keeps lines at the top and bottom. The right half's cell is empty. At DPR 1 and 2 both halves stay clean.

What else changed:

  • At DPR 1 and 2, no pixel in the whole panel differs.
  • At fractional ratios on main, the dark theme shows faint full-width seams at row boundaries, 2/255 or less from the background. This branch removes them, which is why the whole-panel diffs there count 11k to 40k pixels.
  • No glyph pixel differs in any row.
  • The visible cursor block can move by up to 1 device px. At 2.2 it starts 1 px lower and is still solid.
  • A handful of single pixels at the panel's edge or padding corner differ by 1 to 8 levels.

Driver: capture.mjs, compose.mjs, pair.mjs. Raw PNGs and JSON: raw-captures-21641.tar.gz. Fixture matrix: matrix.md.

Verification log
  • Proof audit, pass 1 (matrix derived from the diff): blink rows are recordings and cursor-off frames are stills. It found that the bug needs row edges on fractional device pixels, so the captures use an 11 px terminal font. The cursor shape comes from the terminal's escape codes; the app has no setting for it.
  • Proof audit, pass 2: SUFFICIENT. The SHAs match, and 8d3b061121..a1c2f1e5f3 touches only the three PR files. Every still's cursor-cell count was recomputed from the raw PNGs and matches. All 8 block and bar recordings show the fringe in 7 of 7 off frames on main at a fractional ratio and in 0 of 7 on this branch; at DPR 1 and 2, both show 0. The auditor rebuilt S5 from the driver on fresh isolated servers: after was 0, before was 34, and both whole panels came out pixel-identical to the stored captures.
  • Tests on the local merge a1c2f1e5f3: surface.test.ts passes 28/28. renderer.browser.test.ts (real canvas, Chromium) passes 10/10, and all 10 fail with main's renderer.ts swapped in.
  • CI on head 2a5ca7fae5: every check succeeded, including Build and Typecheck, Lint, Test Web and the Test Server shards. GitHub's merge-conflict check against the current base was still pending. CI has not run on a main merge, because none is pushed.
  • Not verified:
    • Underline cursor (optional in the matrix).
    • Bar cursor in light theme at 2.2. Its parts are covered by S9, R8 and S7.
    • Hollow unfocused cursor. It never blinks, so it can't show this bug.
    • A remnant specific to an erased Powerline separator: not reproduced on main; only the generic row seam shows.
    • Desktop app with View > Zoom In, and a real HiDPI display. The ratio was emulated in headless Chromium.
    • Windows and Linux fractional display scaling.
  • Captured and audited by Claude Opus 5.5 via Claude Code in T3 Code.
  • Code review on head d1cc00b55b (read-only, both reviewers run in parallel). Both agree that snapping row tops to device pixels (renderer.ts rowTop) is the right and minimal fix for the top and bottom lines. They found no regression in selection, wide characters, Powerline glyphs, theme changes or resize. The per-blink cost is one getTransform() per render, which is negligible. Nothing outside apps/web is touched.
    • Reviewer A, Claude Sonnet 5.5: MERGE. It calls the column-0 edge (below) a pre-existing follow-up, not a blocker.
    • Reviewer B, Claude Opus 5.5: FIX_FIRST. The same fringe still appears on the vertical edge when the cursor is in column 0, because the cursor and the row fill both start at padding = 4 CSS px, which is 8.76 device px at a 2.19 ratio. The last column's right edge has the same problem. The tests miss it because they use cursorX: 1, and at 1.25 the padding lands on a whole pixel. Suggested fix: fill the row background across the full canvas width, or snap the x edges too, and add a cursorX: 0 test case.
    • Minor: underline and strikethrough decorations still use metrics.height. That stays within one device pixel and inside the row.

Checks

All checks passed

Added 1 commit

  • fix(web): the terminal cursor no longer leaves faint lines when it blinks offd0eea17
Synced from GitHub

Approvability

Verdict: Approved at d0eea17

Macroscope's review found this PR approvable — This is a focused terminal rendering bug fix that snaps row repaint boundaries at fractional device-pixel ratios, with comprehensive browser regression coverage and no configuration, schema, or deployment impact. The remaining changes only update test mocks.

You can add or adjust custom eligibility rules. Learn more.

Added 1 commit

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 09033fa7-63a5-4355-9629-7c9dc9611ca4
📥 Commits

Reviewing files that changed from the base of the PR and between cd667ddf81bc1db9567399c7ad427206ff685060 and 2a5ca7fae59e7ad59caaceb32822f72d7d16a608.

📒 Files selected for processing: 1
  • apps/web/src/terminal/ghostty/surface.test.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.

📝 Walkthrough

renderGhosttySnapshot aligns row positions to device pixels and uses the resulting row height for rendering row content and cursors. Browser tests cover cursor and Powerline separator repainting at two fractional device-pixel ratios.

Changes: Ghostty row alignment

Layer / File(s)Summary
Align rendered rows
apps/web/src/terminal/ghostty/renderer.ts
The renderer rounds row positions using the canvas vertical scale. It uses the resulting row height for backgrounds, selection fills, text clipping, and cursors. The Powerline separator receives explicit rendered dimensions.
Test row alignment and repainting
apps/web/src/terminal/ghostty/renderer.browser.test.ts, apps/web/src/terminal/ghostty/surface.test.ts
Browser tests check that cursor styles and Powerline separators leave no non-background pixels after partial repainting at device-pixel ratios 1.25 and 2.2. The canvas test context provides getTransform.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: flamboh

Merge Risk: ⚪ Minimal · up to 2a5ca

No actionable merge-blocking risk was established for this rendering change.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the main fix: preventing faint terminal cursor lines after the cursor blinks off.
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
Description checkPassedThe pull request includes all required sections: Problem, Change, Scope and approval, and Verification. It provides reproduction context, linked issue and maintainer approval, focused test results, ma…
Full details: Description check

Explanation

The pull request includes all required sections: Problem, Change, Scope and approval, and Verification. It provides reproduction context, linked issue and maintainer approval, focused test results, manual evidence, limitations, and the agent and harness used.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Added 3 commits

  • Merge remote-tracking branch 'upstream/main' into fix/11402-terminal-cursor-fringeb13b926
  • fix(web): Powerline separators repaint within their snapped row90cee20
  • Merge remote-tracking branch 'upstream/main' into fix/11402-terminal-cursor-fringecd667dd
Synced from GitHub

Merged main, where both tests that failed this PR's CI are fixed (#21699, #21893). #5607 landed in the meantime and draws Powerline separators with the unsnapped cell height, so 90cee20220 passes them the row's snapped height and stubs getTransform in its test. A new browser case shows the unsnapped triangle leaving 1 pixel below its row at both ratios. Description updated to match.

Added 2 commits

  • Merge remote-tracking branch 'upstream/main' into fix/11402-terminal-cursor-fringe2a5ca7f
  • Merge branch 'main' into fix/11402-terminal-cursor-fringed1cc00b