From c5529fb5f3d70a223a79c7c8d79acee3ba3d92a9 Mon Sep 17 00:00:00 2001 From: Osmel Mora <10142809+osmelmora@users.noreply.github.com> Date: Sun, 25 Oct 2026 14:52:17 +0100 Subject: [PATCH 1/2] fix(web): terminal Powerline caps and slants fill their cells Only the two solid arrows were drawn from the cell edges. The rest of U+E0B0-E0BF went through the font, which insets them. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/terminal/ghostty/renderer.ts | 107 ++++++++++++++++------ 1 file changed, 81 insertions(+), 26 deletions(-) diff --git a/apps/web/src/terminal/ghostty/renderer.ts b/apps/web/src/terminal/ghostty/renderer.ts index 29051bb3c047f..6a3d0f099c37d 100644 --- a/apps/web/src/terminal/ghostty/renderer.ts +++ b/apps/web/src/terminal/ghostty/renderer.ts @@ -18,8 +18,33 @@ export interface GhosttyCellRange { } const DEFAULT_SELECTION_BACKGROUND = "rgba(72, 122, 191, 0.35)"; -const POWERLINE_SOLID_RIGHT = "\ue0b0"; -const POWERLINE_SOLID_LEFT = "\ue0b2"; +const POWERLINE_LINE_WIDTH = 1; + +type CellPoint = readonly [x: number, y: number]; +type PowerlineShape = + | { readonly kind: "fill"; readonly points: readonly CellPoint[] } + | { readonly kind: "stroke"; readonly points: readonly CellPoint[] } + | { readonly kind: "cap"; readonly flatEdge: "left" | "right"; readonly filled: boolean }; + +// prettier-ignore +const POWERLINE_SHAPES: ReadonlyMap = new Map([ + ["\ue0b0", { kind: "fill", points: [[0, 0], [1, 0.5], [0, 1]] }], + ["\ue0b1", { kind: "stroke", points: [[0, 0], [1, 0.5], [0, 1]] }], + ["\ue0b2", { kind: "fill", points: [[1, 0], [0, 0.5], [1, 1]] }], + ["\ue0b3", { kind: "stroke", points: [[1, 0], [0, 0.5], [1, 1]] }], + ["\ue0b4", { kind: "cap", flatEdge: "left", filled: true }], + ["\ue0b5", { kind: "cap", flatEdge: "left", filled: false }], + ["\ue0b6", { kind: "cap", flatEdge: "right", filled: true }], + ["\ue0b7", { kind: "cap", flatEdge: "right", filled: false }], + ["\ue0b8", { kind: "fill", points: [[0, 0], [1, 1], [0, 1]] }], + ["\ue0b9", { kind: "stroke", points: [[0, 0], [1, 1]] }], + ["\ue0ba", { kind: "fill", points: [[1, 0], [1, 1], [0, 1]] }], + ["\ue0bb", { kind: "stroke", points: [[1, 0], [0, 1]] }], + ["\ue0bc", { kind: "fill", points: [[0, 0], [1, 0], [0, 1]] }], + ["\ue0bd", { kind: "stroke", points: [[1, 0], [0, 1]] }], + ["\ue0be", { kind: "fill", points: [[0, 0], [1, 0], [1, 1]] }], + ["\ue0bf", { kind: "stroke", points: [[0, 0], [1, 1]] }], +]); function cssColor(color: GhosttyColor): string { return `rgb(${color.r}, ${color.g}, ${color.b})`; @@ -35,28 +60,49 @@ function sameTextStyle(left: GhosttyCell, right: GhosttyCell): boolean { ); } -function isSolidPowerlineSeparator(text: string): boolean { - return text === POWERLINE_SOLID_RIGHT || text === POWERLINE_SOLID_LEFT; -} - -// Fallback fonts inset or scale these private-use glyphs, leaving a gap where -// the separator should meet the next cell. Fill the triangle from the cell's -// own edges instead, as native terminals do. -function fillSolidPowerlineSeparator( +// Fonts inset or scale these private-use glyphs, leaving gaps where they should +// meet the neighboring cells. Draw them from the cell's own edges, as Ghostty does. +function drawPowerlineShape( context: CanvasRenderingContext2D, - text: string, + shape: PowerlineShape, + color: string, left: number, top: number, metrics: GhosttyCellMetrics, ): void { - const right = left + metrics.width; - const [base, point] = text === POWERLINE_SOLID_RIGHT ? [left, right] : [right, left]; + const { width, height } = metrics; + const filled = shape.kind === "fill" || (shape.kind === "cap" && shape.filled); + context.save(); + if (!filled) { + context.beginPath(); + context.rect(left, top, width, height); + context.clip(); + } context.beginPath(); - context.moveTo(base, top); - context.lineTo(point, top + metrics.height / 2); - context.lineTo(base, top + metrics.height); - context.closePath(); - context.fill(); + if (shape.kind === "cap") { + const inset = filled ? 0 : POWERLINE_LINE_WIDTH / 2; + const capTop = top + inset; + const capBottom = top + height - inset; + const radius = Math.min(width - inset, (capBottom - capTop) / 2); + const flatX = shape.flatEdge === "left" ? left : left + width; + const bulgeX = shape.flatEdge === "left" ? flatX + radius : flatX - radius; + context.moveTo(flatX, capTop); + context.arcTo(bulgeX, capTop, bulgeX, capTop + radius, radius); + context.lineTo(bulgeX, capBottom - radius); + context.arcTo(bulgeX, capBottom, flatX, capBottom, radius); + } else { + for (const [x, y] of shape.points) context.lineTo(left + x * width, top + y * height); + } + if (filled) { + context.fillStyle = color; + context.fill(); + } else { + context.strokeStyle = color; + context.lineWidth = POWERLINE_LINE_WIDTH; + context.lineCap = "butt"; + context.stroke(); + } + context.restore(); } function ghosttyTextRunEnd( @@ -72,7 +118,7 @@ function ghosttyTextRunEnd( end += 1; continue; } - if (next.text.length === 0 || isSolidPowerlineSeparator(next.text) || !sameStyle(next)) break; + if (next.text.length === 0 || POWERLINE_SHAPES.has(next.text) || !sameStyle(next)) break; end += 1; } return end; @@ -216,12 +262,13 @@ export function renderGhosttySnapshot(options: { runStart += 1; continue; } - if (isSolidPowerlineSeparator(first.text)) { + const powerlineShape = POWERLINE_SHAPES.get(first.text); + if (powerlineShape) { if (!first.invisible) { - context.fillStyle = cssColor(first.foreground); - fillSolidPowerlineSeparator( + drawPowerlineShape( context, - first.text, + powerlineShape, + cssColor(first.foreground), padding + runStart * metrics.width, top, metrics, @@ -299,10 +346,18 @@ export function renderGhosttySnapshot(options: { context.fillRect(left, top, metrics.width, metrics.height); const cell = snapshot.rowData[snapshot.cursorY]?.cells[snapshot.cursorX]; if (cell?.text) { - context.fillStyle = cssColor(snapshot.background); - if (isSolidPowerlineSeparator(cell.text)) { - fillSolidPowerlineSeparator(context, cell.text, left, top, metrics); + const powerlineShape = POWERLINE_SHAPES.get(cell.text); + if (powerlineShape) { + drawPowerlineShape( + context, + powerlineShape, + cssColor(snapshot.background), + left, + top, + metrics, + ); } else { + context.fillStyle = cssColor(snapshot.background); context.font = fontForCell(cell, fontSize, fontFamily); context.fillText(cell.text, left, top + metrics.baseline, metrics.width); } From ba5ea8c9954295b519cf2dc66a971abfd3e607a6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 08:27:10 +0000 Subject: [PATCH 2/2] test(web): Powerline slants fill their cell corners Co-Authored-By: Claude Opus 5.5 --- .../terminal/ghostty/renderer.browser.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/apps/web/src/terminal/ghostty/renderer.browser.test.ts b/apps/web/src/terminal/ghostty/renderer.browser.test.ts index 3d3aec210d30e..643d33c82966a 100644 --- a/apps/web/src/terminal/ghostty/renderer.browser.test.ts +++ b/apps/web/src/terminal/ghostty/renderer.browser.test.ts @@ -168,4 +168,43 @@ describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio", expect(isDarkAt(context, x.outside, 12.5)).toBe(true); expect(isDarkAt(context, x.flat, 12.5)).toBe(false); }); + + // Cell 1 spans x 11.8 to 19.6 and row 0 spans y 4 to 21 in CSS pixels. + it.each([ + ["lower left", "\ue0b8", { filled: [12.3, 20.5], empty: [19.1, 4.5] }], + ["lower right", "\ue0ba", { filled: [19.1, 20.5], empty: [12.3, 4.5] }], + ["upper left", "\ue0bc", { filled: [12.3, 4.5], empty: [19.1, 20.5] }], + ["upper right", "\ue0be", { filled: [19.1, 4.5], empty: [12.3, 20.5] }], + ])("fills the %s slant into its cell corner", (_corner, text, point) => { + const context = scaledContext(scale); + renderGhosttySnapshot({ + ...layout, + context, + snapshot: { + cols: 3, + rows: 1, + 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: [ + { + cells: [blank, { ...blank, text }, blank], + text: "", + isWrapContinuation: false, + wrapsToNext: false, + }, + ], + }, + forceFull: true, + cursorOn: false, + }); + expect(isDarkAt(context, point.filled[0]!, point.filled[1]!)).toBe(true); + expect(isDarkAt(context, point.empty[0]!, point.empty[1]!)).toBe(false); + }); });