From d0eea17daadafe01f17a1239cbb627dd4cb76175 Mon Sep 17 00:00:00 2001 From: "Nick T." <73005126+tiliakoos@users.noreply.github.com> Date: Mon, 19 Oct 2026 06:04:50 -0400 Subject: [PATCH 1/4] fix(web): the terminal cursor no longer leaves faint lines when it blinks off At a fractional device pixel ratio, row edges fell between device pixels, so the blink-off repaint blended over the cursor's top and bottom edges instead of replacing them. Rows now start on whole device pixels. --- .../terminal/ghostty/renderer.browser.test.ts | 80 +++++++++++++++++++ .../web/src/terminal/ghostty/renderer.test.ts | 4 + apps/web/src/terminal/ghostty/renderer.ts | 28 ++++--- apps/web/src/terminal/ghostty/surface.test.ts | 1 + 4 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 apps/web/src/terminal/ghostty/renderer.browser.test.ts diff --git a/apps/web/src/terminal/ghostty/renderer.browser.test.ts b/apps/web/src/terminal/ghostty/renderer.browser.test.ts new file mode 100644 index 0000000000000..ac87965773303 --- /dev/null +++ b/apps/web/src/terminal/ghostty/renderer.browser.test.ts @@ -0,0 +1,80 @@ +import { describe, expect, it } from "vite-plus/test"; + +import type { GhosttyCell, GhosttySnapshot } from "./core"; +import { renderGhosttySnapshot } from "./renderer"; + +const background = { r: 255, g: 255, b: 255 }; + +const blank: GhosttyCell = { + text: "", + wide: 0, + foreground: { r: 0, g: 0, b: 0 }, + background, + bold: false, + italic: false, + invisible: false, + strikethrough: false, + overline: false, + underline: false, + selected: false, +}; + +/** Counts device pixels that are not the terminal background. */ +function pixelsOffBackground(context: CanvasRenderingContext2D): number { + const { data } = context.getImageData(0, 0, context.canvas.width, context.canvas.height); + let count = 0; + for (let index = 0; index < data.length; index += 4) { + if (data[index] !== 255 || data[index + 1] !== 255 || data[index + 2] !== 255) count += 1; + } + return count; +} + +describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio", (scale) => { + it.each([ + ["bar", 0], + ["block", 1], + ["underline", 2], + ["hollow block", 3], + ])("erases a %s cursor completely when it blinks off", (_name, cursorStyle) => { + const canvas = document.createElement("canvas"); + canvas.width = Math.round(40 * scale); + canvas.height = Math.round(60 * scale); + const context = canvas.getContext("2d"); + if (!context) throw new Error("2D canvas unavailable"); + context.setTransform(scale, 0, 0, scale, 0, 0); + const snapshot: GhosttySnapshot = { + cols: 3, + rows: 3, + foreground: { r: 0, g: 0, b: 0 }, + background, + cursor: { r: 0, g: 0, b: 0 }, + cursorX: 1, + cursorY: 1, + cursorVisible: true, + cursorBlinking: true, + cursorStyle, + dirtyRows: new Set(), + rowData: [0, 1, 2].map(() => ({ + cells: [blank, blank, blank], + text: "", + isWrapContinuation: false, + wrapsToNext: false, + })), + }; + const options = { + context, + snapshot, + metrics: { width: 8, height: 17, baseline: 13 }, + fontSize: 13, + fontFamily: "monospace", + padding: 4, + originY: 4, + }; + + renderGhosttySnapshot({ ...options, forceFull: true, cursorOn: true }); + expect(pixelsOffBackground(context)).toBeGreaterThan(0); + + renderGhosttySnapshot({ ...options, forceFull: false, cursorOn: false, previousCursorY: 1 }); + expect(pixelsOffBackground(context)).toBe(0); + }); +}); diff --git a/apps/web/src/terminal/ghostty/renderer.test.ts b/apps/web/src/terminal/ghostty/renderer.test.ts index 6616f45ab489e..a0361d66929ad 100644 --- a/apps/web/src/terminal/ghostty/renderer.test.ts +++ b/apps/web/src/terminal/ghostty/renderer.test.ts @@ -79,6 +79,7 @@ describe("renderGhosttySnapshot", () => { clip: () => {}, fillRect: (...args: number[]) => fillRectCalls.push(args), fillText: () => {}, + getTransform: () => ({ d: 1 }), rect: () => {}, resetTransform: () => {}, restore: () => {}, @@ -135,6 +136,7 @@ describe("renderGhosttySnapshot", () => { clip: () => {}, fillRect: () => {}, fillText: (...args: unknown[]) => fillTextCalls.push(args), + getTransform: () => ({ d: 1 }), rect: () => {}, resetTransform: () => {}, restore: () => {}, @@ -184,6 +186,7 @@ describe("renderGhosttySnapshot", () => { clip: () => {}, fillRect: () => {}, fillText: (...args: unknown[]) => fillTextCalls.push(args), + getTransform: () => ({ d: 1 }), rect: () => {}, resetTransform: () => {}, restore: () => {}, @@ -238,6 +241,7 @@ describe("renderGhosttySnapshot", () => { if (height === 16) clearedRows.push(top); }, fillText: () => {}, + getTransform: () => ({ d: 1 }), rect: () => {}, resetTransform: () => {}, restore: () => {}, diff --git a/apps/web/src/terminal/ghostty/renderer.ts b/apps/web/src/terminal/ghostty/renderer.ts index 8be5bb873bcbb..22e2825dfc9ef 100644 --- a/apps/web/src/terminal/ghostty/renderer.ts +++ b/apps/web/src/terminal/ghostty/renderer.ts @@ -121,6 +121,10 @@ export function renderGhosttySnapshot(options: { const selectionBackground = options.selectionBackground ?? DEFAULT_SELECTION_BACKGROUND; const hoveredLinkRange = options.hoveredLinkRange ?? null; const originY = options.originY ?? padding; + // Rows start on whole device pixels, so repainting a row replaces every pixel + // the last frame drew in it, including a blinking cursor's edges. + const scale = context.getTransform().d; + const rowTop = (row: number) => Math.round((originY + row * metrics.height) * scale) / scale; const rowsToDraw = forceFull ? Array.from({ length: snapshot.rows }, (_, index) => index) : [...snapshot.dirtyRows]; @@ -148,10 +152,11 @@ export function renderGhosttySnapshot(options: { for (const rowIndex of rowsToDraw) { const row = snapshot.rowData[rowIndex]; if (!row) continue; - const top = originY + rowIndex * metrics.height; + const top = rowTop(rowIndex); + const height = rowTop(rowIndex + 1) - top; context.fillStyle = cssColor(snapshot.background); - context.fillRect(padding, top, snapshot.cols * metrics.width, metrics.height); + context.fillRect(padding, top, snapshot.cols * metrics.width, height); let backgroundStart = 0; while (backgroundStart < row.cells.length) { @@ -174,11 +179,11 @@ export function renderGhosttySnapshot(options: { const width = (backgroundEnd - backgroundStart) * metrics.width; if (!ghosttyColorsEqual(first.background, snapshot.background)) { context.fillStyle = cssColor(first.background); - context.fillRect(left, top, width, metrics.height); + context.fillRect(left, top, width, height); } if (first.selected) { context.fillStyle = selectionBackground; - context.fillRect(left, top, width, metrics.height); + context.fillRect(left, top, width, height); } } backgroundStart = backgroundEnd; @@ -204,7 +209,7 @@ export function renderGhosttySnapshot(options: { padding + runStart * metrics.width, top, (runEnd - runStart) * metrics.width, - metrics.height, + height, ); context.clip(); context.font = fontForCell(first, fontSize, fontFamily); @@ -245,20 +250,21 @@ export function renderGhosttySnapshot(options: { if (cursorOn && snapshot.cursorVisible && snapshot.cursorX >= 0 && snapshot.cursorY >= 0) { const left = padding + snapshot.cursorX * metrics.width; - const top = originY + snapshot.cursorY * metrics.height; + const top = rowTop(snapshot.cursorY); + const height = rowTop(snapshot.cursorY + 1) - top; context.fillStyle = cssColor(snapshot.cursor); if (!focused) { context.strokeStyle = cssColor(snapshot.cursor); - context.strokeRect(left + 0.5, top + 0.5, metrics.width - 1, metrics.height - 1); + context.strokeRect(left + 0.5, top + 0.5, metrics.width - 1, height - 1); } else if (snapshot.cursorStyle === 0) { - context.fillRect(left, top, 2, metrics.height); + context.fillRect(left, top, 2, height); } else if (snapshot.cursorStyle === 2) { - context.fillRect(left, top + metrics.height - 2, metrics.width, 2); + context.fillRect(left, top + height - 2, metrics.width, 2); } else if (snapshot.cursorStyle === 3) { context.strokeStyle = cssColor(snapshot.cursor); - context.strokeRect(left + 0.5, top + 0.5, metrics.width - 1, metrics.height - 1); + context.strokeRect(left + 0.5, top + 0.5, metrics.width - 1, height - 1); } else { - context.fillRect(left, top, metrics.width, metrics.height); + context.fillRect(left, top, metrics.width, height); const cell = snapshot.rowData[snapshot.cursorY]?.cells[snapshot.cursorX]; if (cell?.text) { context.font = fontForCell(cell, fontSize, fontFamily); diff --git a/apps/web/src/terminal/ghostty/surface.test.ts b/apps/web/src/terminal/ghostty/surface.test.ts index f967fcff23fdc..e60dc76e74984 100644 --- a/apps/web/src/terminal/ghostty/surface.test.ts +++ b/apps/web/src/terminal/ghostty/surface.test.ts @@ -133,6 +133,7 @@ describe("GhosttyTerminalSurface visibility", () => { canvas, beginPath() {}, clip() {}, + getTransform: () => ({ d: 1 }), rect() {}, resetTransform() {}, restore() {}, From eff31ae7231444d393f61b182e46229ef6d0f530 Mon Sep 17 00:00:00 2001 From: "Nick T." <73005126+tiliakoos@users.noreply.github.com> Date: Mon, 19 Oct 2026 06:18:38 -0400 Subject: [PATCH 2/4] ci: rerun checks From 90cee202204a586366e0d5dffc55dc274cf19d92 Mon Sep 17 00:00:00 2001 From: "Nick T." <73005126+tiliakoos@users.noreply.github.com> Date: Mon, 19 Oct 2026 16:43:51 -0400 Subject: [PATCH 3/4] fix(web): Powerline separators repaint within their snapped row #5607's separators came in with main and still used the unsnapped cell height, so a separator could leave a pixel below its row; its test mock also lacked getTransform. --- .../terminal/ghostty/renderer.browser.test.ts | 67 ++++++++++++++----- .../web/src/terminal/ghostty/renderer.test.ts | 1 + apps/web/src/terminal/ghostty/renderer.ts | 14 ++-- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/apps/web/src/terminal/ghostty/renderer.browser.test.ts b/apps/web/src/terminal/ghostty/renderer.browser.test.ts index ac87965773303..1eaa784668175 100644 --- a/apps/web/src/terminal/ghostty/renderer.browser.test.ts +++ b/apps/web/src/terminal/ghostty/renderer.browser.test.ts @@ -29,6 +29,25 @@ function pixelsOffBackground(context: CanvasRenderingContext2D): number { return count; } +/** A 40 by 60 CSS pixel canvas drawn at the given device pixel ratio. */ +function scaledContext(scale: number): CanvasRenderingContext2D { + const canvas = document.createElement("canvas"); + canvas.width = Math.round(40 * scale); + canvas.height = Math.round(60 * scale); + const context = canvas.getContext("2d"); + if (!context) throw new Error("2D canvas unavailable"); + context.setTransform(scale, 0, 0, scale, 0, 0); + return context; +} + +const layout = { + metrics: { width: 8, height: 17, baseline: 13 }, + fontSize: 13, + fontFamily: "monospace", + padding: 4, + originY: 4, +}; + describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio", (scale) => { it.each([ ["bar", 0], @@ -36,12 +55,7 @@ describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio", ["underline", 2], ["hollow block", 3], ])("erases a %s cursor completely when it blinks off", (_name, cursorStyle) => { - const canvas = document.createElement("canvas"); - canvas.width = Math.round(40 * scale); - canvas.height = Math.round(60 * scale); - const context = canvas.getContext("2d"); - if (!context) throw new Error("2D canvas unavailable"); - context.setTransform(scale, 0, 0, scale, 0, 0); + const context = scaledContext(scale); const snapshot: GhosttySnapshot = { cols: 3, rows: 3, @@ -61,15 +75,7 @@ describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio", wrapsToNext: false, })), }; - const options = { - context, - snapshot, - metrics: { width: 8, height: 17, baseline: 13 }, - fontSize: 13, - fontFamily: "monospace", - padding: 4, - originY: 4, - }; + const options = { ...layout, context, snapshot }; renderGhosttySnapshot({ ...options, forceFull: true, cursorOn: true }); expect(pixelsOffBackground(context)).toBeGreaterThan(0); @@ -77,4 +83,35 @@ describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio", renderGhosttySnapshot({ ...options, forceFull: false, cursorOn: false, previousCursorY: 1 }); expect(pixelsOffBackground(context)).toBe(0); }); + + it("erases a Powerline separator completely when only its row repaints", () => { + const context = scaledContext(scale); + const firstRow = (cell: GhosttyCell): GhosttySnapshot => ({ + cols: 3, + rows: 3, + foreground: { r: 0, g: 0, b: 0 }, + background, + cursor: { r: 0, g: 0, b: 0 }, + cursorX: -1, + cursorY: -1, + cursorVisible: false, + cursorBlinking: false, + cursorStyle: 1, + dirtyRows: new Set([0]), + rowData: [cell, blank, blank].map((middle) => ({ + cells: [blank, middle, blank], + text: "", + isWrapContinuation: false, + wrapsToNext: false, + })), + }); + const options = { ...layout, context, forceFull: false, cursorOn: false }; + + renderGhosttySnapshot({ ...options, snapshot: firstRow(blank), forceFull: true }); + renderGhosttySnapshot({ ...options, snapshot: firstRow({ ...blank, text: "\ue0b0" }) }); + expect(pixelsOffBackground(context)).toBeGreaterThan(0); + + renderGhosttySnapshot({ ...options, snapshot: firstRow(blank) }); + expect(pixelsOffBackground(context)).toBe(0); + }); }); diff --git a/apps/web/src/terminal/ghostty/renderer.test.ts b/apps/web/src/terminal/ghostty/renderer.test.ts index f95b01a6597b1..a9985d7ef3c62 100644 --- a/apps/web/src/terminal/ghostty/renderer.test.ts +++ b/apps/web/src/terminal/ghostty/renderer.test.ts @@ -85,6 +85,7 @@ describe("renderGhosttySnapshot", () => { fill: () => paths.push(path), fillRect: () => {}, fillText: (...args: unknown[]) => fillTextCalls.push(args), + getTransform: () => ({ d: 1 }), lineTo: (x: number, y: number) => path.push([x, y]), moveTo: (x: number, y: number) => path.push([x, y]), rect: () => {}, diff --git a/apps/web/src/terminal/ghostty/renderer.ts b/apps/web/src/terminal/ghostty/renderer.ts index 8477b739a3317..21686d51f5920 100644 --- a/apps/web/src/terminal/ghostty/renderer.ts +++ b/apps/web/src/terminal/ghostty/renderer.ts @@ -49,14 +49,15 @@ function fillSolidPowerlineSeparator( text: string, left: number, top: number, - metrics: GhosttyCellMetrics, + width: number, + height: number, ): void { - const right = left + metrics.width; + const right = left + width; const [base, point] = text === POWERLINE_SOLID_RIGHT ? [left, right] : [right, left]; context.beginPath(); context.moveTo(base, top); - context.lineTo(point, top + metrics.height / 2); - context.lineTo(base, top + metrics.height); + context.lineTo(point, top + height / 2); + context.lineTo(base, top + height); context.closePath(); context.fill(); } @@ -231,7 +232,8 @@ export function renderGhosttySnapshot(options: { first.text, padding + runStart * metrics.width, top, - metrics, + metrics.width, + height, ); } runStart += 1; @@ -309,7 +311,7 @@ export function renderGhosttySnapshot(options: { if (cell?.text) { context.fillStyle = cssColor(snapshot.background); if (isSolidPowerlineSeparator(cell.text)) { - fillSolidPowerlineSeparator(context, cell.text, left, top, metrics); + fillSolidPowerlineSeparator(context, cell.text, left, top, metrics.width, height); } else { context.font = fontForCell(cell, fontSize, fontFamily); context.fillText(cell.text, left, top + metrics.baseline, metrics.width); From d5702f06608a96649c591d4d683214e6c3830bf0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 06:03:56 +0000 Subject: [PATCH 4/4] fix(web): terminal rows clear the full canvas width on repaint Cell width is measured and usually fractional, so a cursor in the last column (or the first, at fractional zoom) has antialiased edges on the row's horizontal boundary. Clearing only the grid width left those pixels partially blended after the cursor blinked off. AI-assisted; verified with the tests and tools listed above. --- .../src/terminal/ghostty/renderer.browser.test.ts | 4 ++-- apps/web/src/terminal/ghostty/renderer.ts | 12 +++++++----- apps/web/src/terminal/ghostty/surface.test.ts | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/web/src/terminal/ghostty/renderer.browser.test.ts b/apps/web/src/terminal/ghostty/renderer.browser.test.ts index 1eaa784668175..eb48b04167748 100644 --- a/apps/web/src/terminal/ghostty/renderer.browser.test.ts +++ b/apps/web/src/terminal/ghostty/renderer.browser.test.ts @@ -41,7 +41,7 @@ function scaledContext(scale: number): CanvasRenderingContext2D { } const layout = { - metrics: { width: 8, height: 17, baseline: 13 }, + metrics: { width: 7.8, height: 17, baseline: 13 }, fontSize: 13, fontFamily: "monospace", padding: 4, @@ -62,7 +62,7 @@ describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio", foreground: { r: 0, g: 0, b: 0 }, background, cursor: { r: 0, g: 0, b: 0 }, - cursorX: 1, + cursorX: 2, cursorY: 1, cursorVisible: true, cursorBlinking: true, diff --git a/apps/web/src/terminal/ghostty/renderer.ts b/apps/web/src/terminal/ghostty/renderer.ts index 491218d5e1214..98e3699ab314b 100644 --- a/apps/web/src/terminal/ghostty/renderer.ts +++ b/apps/web/src/terminal/ghostty/renderer.ts @@ -146,10 +146,12 @@ export function renderGhosttySnapshot(options: { const selectionBackground = options.selectionBackground ?? DEFAULT_SELECTION_BACKGROUND; const hoveredLinkRange = options.hoveredLinkRange ?? null; const originY = options.originY ?? padding; - // Rows start on whole device pixels, so repainting a row replaces every pixel - // the last frame drew in it, including a blinking cursor's edges. - const scale = context.getTransform().d; - const rowTop = (row: number) => Math.round((originY + row * metrics.height) * scale) / scale; + // Rows start on whole device pixels and clear the full canvas width, so repainting + // a row replaces every pixel the last frame drew in it, including a cursor's edges. + const transform = context.getTransform(); + const rowTop = (row: number) => + Math.round((originY + row * metrics.height) * transform.d) / transform.d; + const rowWidth = context.canvas.width / transform.a; const rowsToDraw = forceFull ? Array.from({ length: snapshot.rows }, (_, index) => index) : [...snapshot.dirtyRows]; @@ -181,7 +183,7 @@ export function renderGhosttySnapshot(options: { const height = rowTop(rowIndex + 1) - top; context.fillStyle = cssColor(snapshot.background); - context.fillRect(padding, top, snapshot.cols * metrics.width, height); + context.fillRect(0, top, rowWidth, height); let backgroundStart = 0; while (backgroundStart < row.cells.length) { diff --git a/apps/web/src/terminal/ghostty/surface.test.ts b/apps/web/src/terminal/ghostty/surface.test.ts index 172be1174980e..de0821c65b58c 100644 --- a/apps/web/src/terminal/ghostty/surface.test.ts +++ b/apps/web/src/terminal/ghostty/surface.test.ts @@ -127,7 +127,7 @@ describe("GhosttyTerminalSurface visibility", () => { canvas, beginPath() {}, clip() {}, - getTransform: () => ({ d: 1 }), + getTransform: () => ({ a: 1, d: 1 }), rect() {}, resetTransform() {}, restore() {},