The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 22:15 UTC
fix(web): draw rounded powerline caps to fill the terminal cell (#34552)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
João Ferro committed
Nov 11, 2026 at 21:38 UTC
01b815ffc29b634a7ede198e67c60460319fc1cb
2 files changed
+81
-5
apps/web/src/terminal/ghostty/renderer.browser.test.ts
+54
@@ -29,6 +29,13 @@ function pixelsOffBackground(context: CanvasRenderingContext2D): number {
29
return count;
30
}
31
32
+/** Whether the device pixel under a CSS pixel position is closer to black than white. */
33
+function isDarkAt(context: CanvasRenderingContext2D, x: number, y: number): boolean {
34
+ const { a, d } = context.getTransform();
35
+ const { data } = context.getImageData(Math.floor(x * a), Math.floor(y * d), 1, 1);
36
+ return data[0]! < 128 && data[1]! < 128 && data[2]! < 128;
37
+}
38
+
39
/** A 40 by 60 CSS pixel canvas drawn at the given device pixel ratio. */
40
function scaledContext(scale: number): CanvasRenderingContext2D {
41
const canvas = document.createElement("canvas");
@@ -114,4 +121,51 @@ describe.each([1.25, 2.2])("renderGhosttySnapshot at a %sx device pixel ratio",
121
renderGhosttySnapshot({ ...options, snapshot: firstRow(blank) });
122
expect(pixelsOffBackground(context)).toBe(0);
123
});
124
+
125
+ // Cell 1 spans x 11.8 to 19.6 and row 0 spans y 4 to 21 in CSS pixels.
126
+ it.each([
127
+ ["right", "\ue0b4", { flat: 12.3, round: 19.1, neighbour: 0, outside: 11.3 }],
128
+ ["left", "\ue0b6", { flat: 19.1, round: 12.3, neighbour: 2, outside: 20.1 }],
129
+ ])("fills the rounded %s cap to the cell edges, under a block cursor too", (_side, text, x) => {
130
+ const context = scaledContext(scale);
131
+ const segment = { ...blank, background: { r: 0, g: 0, b: 0 } };
132
+ const cells = [blank, { ...blank, text }, blank];
133
+ cells[x.neighbour] = segment;
134
+ const snapshot = (cursorVisible: boolean): GhosttySnapshot => ({
135
+ cols: 3,
136
+ rows: 1,
137
+ foreground: { r: 0, g: 0, b: 0 },
138
+ background,
139
+ cursor: { r: 0, g: 0, b: 0 },
140
+ cursorX: 1,
141
+ cursorY: 0,
142
+ cursorVisible,
143
+ cursorBlinking: false,
144
+ cursorStyle: 1,
145
+ dirtyRows: new Set([0]),
146
+ rowData: [{ cells, text: "", isWrapContinuation: false, wrapsToNext: false }],
147
+ });
148
+
149
+ renderGhosttySnapshot({
150
+ ...layout,
151
+ context,
152
+ snapshot: snapshot(false),
153
+ forceFull: true,
154
+ cursorOn: false,
155
+ });
156
+ expect(isDarkAt(context, x.flat, 4.5)).toBe(true);
157
+ expect(isDarkAt(context, x.flat, 20.5)).toBe(true);
158
+ expect(isDarkAt(context, x.round, 12.5)).toBe(true);
159
+ expect(isDarkAt(context, x.round, 4.5)).toBe(false);
160
+
161
+ renderGhosttySnapshot({
162
+ ...layout,
163
+ context,
164
+ snapshot: snapshot(true),
165
+ forceFull: true,
166
+ cursorOn: true,
167
+ });
168
+ expect(isDarkAt(context, x.outside, 12.5)).toBe(true);
169
+ expect(isDarkAt(context, x.flat, 12.5)).toBe(false);
170
+ });
171
});
apps/web/src/terminal/ghostty/renderer.ts
+27
-5
@@ -20,6 +20,8 @@ export interface GhosttyCellRange {
20
const DEFAULT_SELECTION_BACKGROUND = "rgba(72, 122, 191, 0.35)";
21
const POWERLINE_SOLID_RIGHT = "\ue0b0";
22
const POWERLINE_SOLID_LEFT = "\ue0b2";
23
+const POWERLINE_ROUND_RIGHT = "\ue0b4";
24
+const POWERLINE_ROUND_LEFT = "\ue0b6";
25
26
function cssColor(color: GhosttyColor): string {
27
return `rgb(${color.r}, ${color.g}, ${color.b})`;
@@ -36,12 +38,17 @@ function sameTextStyle(left: GhosttyCell, right: GhosttyCell): boolean {
38
}
39
40
function isSolidPowerlineSeparator(text: string): boolean {
39
- return text === POWERLINE_SOLID_RIGHT || text === POWERLINE_SOLID_LEFT;
41
+ return (
42
+ text === POWERLINE_SOLID_RIGHT ||
43
+ text === POWERLINE_SOLID_LEFT ||
44
+ text === POWERLINE_ROUND_RIGHT ||
45
+ text === POWERLINE_ROUND_LEFT
46
+ );
47
}
48
49
// Fallback fonts inset or scale these private-use glyphs, leaving a gap where
43
-// the separator should meet the next cell. Fill the triangle from the cell's
44
-// own edges instead, as native terminals do.
50
+// the separator should meet the next cell. Fill the triangle or half-ellipse
51
+// from the cell's own edges instead, as native terminals do.
52
function fillSolidPowerlineSeparator(
53
context: CanvasRenderingContext2D,
54
text: string,
@@ -49,12 +56,26 @@ function fillSolidPowerlineSeparator(
56
top: number,
57
width: number,
58
height: number,
59
+ seamOverlap: number,
60
): void {
61
const right = left + width;
62
+ const middle = top + height / 2;
63
+ if (text === POWERLINE_ROUND_RIGHT || text === POWERLINE_ROUND_LEFT) {
64
+ const [base, start, inward] =
65
+ text === POWERLINE_ROUND_RIGHT ? [left, -Math.PI / 2, -1] : [right, Math.PI / 2, 1];
66
+ context.beginPath();
67
+ context.ellipse(base, middle, width, height / 2, 0, start, start + Math.PI);
68
+ context.closePath();
69
+ // Overlap the segment this cap closes so anti-aliasing at a fractional
70
+ // cell edge does not leave a hairline seam.
71
+ context.rect(Math.min(base, base + inward * seamOverlap), top, seamOverlap, height);
72
+ context.fill();
73
+ return;
74
+ }
75
const [base, point] = text === POWERLINE_SOLID_RIGHT ? [left, right] : [right, left];
76
context.beginPath();
77
context.moveTo(base, top);
57
- context.lineTo(point, top + height / 2);
78
+ context.lineTo(point, middle);
79
context.lineTo(base, top + height);
80
context.closePath();
81
context.fill();
@@ -234,6 +255,7 @@ export function renderGhosttySnapshot(options: {
255
top,
256
metrics.width,
257
height,
258
+ 1,
259
);
260
}
261
runStart += 1;
@@ -311,7 +333,7 @@ export function renderGhosttySnapshot(options: {
333
if (cell?.text) {
334
context.fillStyle = cssColor(snapshot.background);
335
if (isSolidPowerlineSeparator(cell.text)) {
314
- fillSolidPowerlineSeparator(context, cell.text, left, top, metrics.width, height);
336
+ fillSolidPowerlineSeparator(context, cell.text, left, top, metrics.width, height, 0);
337
} else {
338
context.font = fontForCell(cell, fontSize, fontFamily);
339
context.fillText(cell.text, left, top + metrics.baseline, metrics.width);