Skip to content

Commit 9fd4175

Browse files
fix(web): solid Powerline separators fill their terminal cell
Fallback fonts inset or scale U+E0B0 and U+E0B2, so Powerline prompts showed a gap or a narrow bar where one segment should flow into the next. Draw those two glyphs as triangles from the cell's own edges, keep them out of batched text runs, and reuse the same fill when a block cursor sits on the cell. Takeover rebuild of the original implementation: one fill helper with the glyph check at each call site instead of a validating helper that returns whether it drew; the Powerline-only test is folded into one renderer integration test. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 61c0212 commit 9fd4175

2 files changed

Lines changed: 28 additions & 43 deletions

File tree

‎apps/web/src/terminal/ghostty/renderer.test.ts‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,10 @@ describe("ghosttyTextRunEnd", () => {
6868
];
6969
expect(ghosttyTextRunEnd(cells, 0, () => true)).toBe(4);
7070
});
71-
72-
it("stops before a built-in Powerline separator", () => {
73-
expect(ghosttyTextRunEnd([cell("a"), cell("\ue0b0"), cell("b")], 0, () => true)).toBe(1);
74-
});
7571
});
7672

7773
describe("renderGhosttySnapshot", () => {
78-
it("draws solid Powerline separators to the terminal cell edges", () => {
74+
it("draws solid Powerline separators to their cell edges instead of as text", () => {
7975
const paths: number[][][] = [];
8076
let path: number[][] = [];
8177
const fillTextCalls: unknown[][] = [];
@@ -100,7 +96,7 @@ describe("renderGhosttySnapshot", () => {
10096
set textBaseline(_value: string) {},
10197
} as unknown as CanvasRenderingContext2D;
10298
const snapshot: GhosttySnapshot = {
103-
cols: 2,
99+
cols: 3,
104100
rows: 1,
105101
foreground: { r: 255, g: 255, b: 255 },
106102
background: { r: 0, g: 0, b: 0 },
@@ -113,8 +109,8 @@ describe("renderGhosttySnapshot", () => {
113109
dirtyRows: new Set([0]),
114110
rowData: [
115111
{
116-
cells: [cell("\ue0b0"), cell("\ue0b2")],
117-
text: "\ue0b0\ue0b2",
112+
cells: [cell("a"), cell("\ue0b0"), cell("\ue0b2")],
113+
text: "a\ue0b0\ue0b2",
118114
isWrapContinuation: false,
119115
wrapsToNext: false,
120116
},
@@ -132,19 +128,19 @@ describe("renderGhosttySnapshot", () => {
132128
cursorOn: false,
133129
});
134130

131+
expect(fillTextCalls).toEqual([["a", 4, 19, 10]]);
135132
expect(paths).toEqual([
136133
[
137-
[4, 4],
138-
[14, 14],
139-
[4, 24],
134+
[14, 4],
135+
[24, 14],
136+
[14, 24],
140137
],
141138
[
142-
[24, 4],
143-
[14, 14],
144-
[24, 24],
139+
[34, 4],
140+
[24, 14],
141+
[34, 24],
145142
],
146143
]);
147-
expect(fillTextCalls).toEqual([]);
148144
});
149145

150146
it("underlines every cell in a hovered wrapped link", () => {

‎apps/web/src/terminal/ghostty/renderer.ts‎

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,24 @@ function isSolidPowerlineSeparator(text: string): boolean {
4141
return text === POWERLINE_SOLID_RIGHT || text === POWERLINE_SOLID_LEFT;
4242
}
4343

44-
// Solid Powerline separators continue one cell's background into the next.
45-
// Font fallback metrics can inset or scale these private-use glyphs, so draw
46-
// their cell-edge geometry directly like native terminal renderers do.
47-
function drawSolidPowerlineSeparator(
44+
// Fallback fonts inset or scale these private-use glyphs, leaving a gap where
45+
// the separator should meet the next cell. Fill the triangle from the cell's
46+
// own edges instead, as native terminals do.
47+
function fillSolidPowerlineSeparator(
4848
context: CanvasRenderingContext2D,
4949
text: string,
5050
left: number,
5151
top: number,
52-
width: number,
53-
height: number,
54-
): boolean {
55-
if (!isSolidPowerlineSeparator(text)) return false;
56-
const right = left + width;
57-
const middle = top + height / 2;
58-
const bottom = top + height;
52+
metrics: GhosttyCellMetrics,
53+
): void {
54+
const right = left + metrics.width;
55+
const [base, point] = text === POWERLINE_SOLID_RIGHT ? [left, right] : [right, left];
5956
context.beginPath();
60-
if (text === POWERLINE_SOLID_RIGHT) {
61-
context.moveTo(left, top);
62-
context.lineTo(right, middle);
63-
context.lineTo(left, bottom);
64-
} else {
65-
context.moveTo(right, top);
66-
context.lineTo(left, middle);
67-
context.lineTo(right, bottom);
68-
}
57+
context.moveTo(base, top);
58+
context.lineTo(point, top + metrics.height / 2);
59+
context.lineTo(base, top + metrics.height);
6960
context.closePath();
7061
context.fill();
71-
return true;
7262
}
7363

7464
export function ghosttyTextRunEnd(
@@ -231,13 +221,12 @@ export function renderGhosttySnapshot(options: {
231221
if (isSolidPowerlineSeparator(first.text)) {
232222
if (!first.invisible) {
233223
context.fillStyle = cssColor(first.foreground);
234-
drawSolidPowerlineSeparator(
224+
fillSolidPowerlineSeparator(
235225
context,
236226
first.text,
237227
padding + runStart * metrics.width,
238228
top,
239-
metrics.width,
240-
metrics.height,
229+
metrics,
241230
);
242231
}
243232
runStart += 1;
@@ -312,11 +301,11 @@ export function renderGhosttySnapshot(options: {
312301
context.fillRect(left, top, metrics.width, metrics.height);
313302
const cell = snapshot.rowData[snapshot.cursorY]?.cells[snapshot.cursorX];
314303
if (cell?.text) {
315-
context.font = fontForCell(cell, fontSize, fontFamily);
316304
context.fillStyle = cssColor(snapshot.background);
317-
if (
318-
!drawSolidPowerlineSeparator(context, cell.text, left, top, metrics.width, metrics.height)
319-
) {
305+
if (isSolidPowerlineSeparator(cell.text)) {
306+
fillSolidPowerlineSeparator(context, cell.text, left, top, metrics);
307+
} else {
308+
context.font = fontForCell(cell, fontSize, fontFamily);
320309
context.fillText(cell.text, left, top + metrics.baseline, metrics.width);
321310
}
322311
}

0 commit comments

Comments
 (0)