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): keep wide terminal glyphs on the cell grid (#27948)
Julius Marminge committed
Nov 11, 2026 at 14:05 UTC
323c0a8d0dd7619ecdb8de87690116e2be3589e7
1 file changed
+71
-11
apps/web/src/terminal/ghostty/renderer.ts
+71
-11
@@ -100,6 +100,55 @@ function ghosttyTextRunEnd(
100
return end;
101
}
102
103
+// Snapshots decode `wide` only for empty cells, so a wide glyph is known by its spacer tail.
104
+function isWideGlyph(cells: readonly GhosttyCell[], index: number): boolean {
105
+ return cells[index + 1]?.wide === GHOSTTY_CELL_WIDE.spacerTail;
106
+}
107
+
108
+// Wide glyphs rarely advance exactly two cells, so each is centred in its own box
109
+// and the narrow text after it restarts at its own column instead of drifting.
110
+function fillGhosttyRunText(
111
+ context: CanvasRenderingContext2D,
112
+ cells: readonly GhosttyCell[],
113
+ start: number,
114
+ end: number,
115
+ text: string,
116
+ left: number,
117
+ baseline: number,
118
+ cellWidth: number,
119
+): void {
120
+ let segment = start;
121
+ while (segment < end) {
122
+ let segmentEnd = segment;
123
+ while (segmentEnd < end && !isWideGlyph(cells, segmentEnd)) segmentEnd += 1;
124
+ if (segmentEnd > segment) {
125
+ const segmentText =
126
+ segment === start && segmentEnd === end
127
+ ? text
128
+ : cells
129
+ .slice(segment, segmentEnd)
130
+ .map((cell) => cell.text)
131
+ .join("");
132
+ context.fillText(
133
+ segmentText,
134
+ left + (segment - start) * cellWidth,
135
+ baseline,
136
+ (segmentEnd - segment) * cellWidth,
137
+ );
138
+ }
139
+ if (segmentEnd === end) break;
140
+ context.textAlign = "center";
141
+ context.fillText(
142
+ cells[segmentEnd]?.text ?? "",
143
+ left + (segmentEnd - start + 1) * cellWidth,
144
+ baseline,
145
+ cellWidth * 2,
146
+ );
147
+ context.textAlign = "start";
148
+ segment = segmentEnd + 2;
149
+ }
150
+}
151
+
152
function fontForCell(cell: GhosttyCell, fontSize: number, fontFamily: string): string {
153
const style = cell.italic ? "italic" : "normal";
154
const weight = cell.bold ? "700" : "400";
@@ -278,11 +327,15 @@ export function renderGhosttySnapshot(options: {
327
context.clip();
328
context.font = fontForCell(first, fontSize, fontFamily);
329
context.fillStyle = cssColor(first.foreground);
281
- context.fillText(
330
+ fillGhosttyRunText(
331
+ context,
332
+ row.cells,
333
+ runStart,
334
+ runEnd,
335
text,
336
padding + runStart * metrics.width,
337
top + metrics.baseline,
285
- (runEnd - runStart) * metrics.width,
338
+ metrics.width,
339
);
340
context.restore();
341
}
@@ -316,27 +369,34 @@ export function renderGhosttySnapshot(options: {
369
const left = padding + snapshot.cursorX * metrics.width;
370
const top = rowTop(snapshot.cursorY);
371
const height = rowTop(snapshot.cursorY + 1) - top;
372
+ const cells = snapshot.rowData[snapshot.cursorY]?.cells ?? [];
373
+ const wide = isWideGlyph(cells, snapshot.cursorX);
374
+ const width = wide ? metrics.width * 2 : metrics.width;
375
context.fillStyle = cssColor(snapshot.cursor);
320
- if (!focused) {
376
+ if (!focused || snapshot.cursorStyle === 3) {
377
context.strokeStyle = cssColor(snapshot.cursor);
322
- context.strokeRect(left + 0.5, top + 0.5, metrics.width - 1, height - 1);
378
+ context.strokeRect(left + 0.5, top + 0.5, width - 1, height - 1);
379
} else if (snapshot.cursorStyle === 0) {
380
context.fillRect(left, top, 2, height);
381
} else if (snapshot.cursorStyle === 2) {
326
- context.fillRect(left, top + height - 2, metrics.width, 2);
327
- } else if (snapshot.cursorStyle === 3) {
328
- context.strokeStyle = cssColor(snapshot.cursor);
329
- context.strokeRect(left + 0.5, top + 0.5, metrics.width - 1, height - 1);
382
+ context.fillRect(left, top + height - 2, width, 2);
383
} else {
331
- context.fillRect(left, top, metrics.width, height);
332
- const cell = snapshot.rowData[snapshot.cursorY]?.cells[snapshot.cursorX];
384
+ const cell = cells[snapshot.cursorX];
385
+ context.fillRect(left, top, width, height);
386
if (cell?.text) {
387
context.fillStyle = cssColor(snapshot.background);
388
if (isSolidPowerlineSeparator(cell.text)) {
389
fillSolidPowerlineSeparator(context, cell.text, left, top, metrics.width, height, 0);
390
} else {
391
context.font = fontForCell(cell, fontSize, fontFamily);
339
- context.fillText(cell.text, left, top + metrics.baseline, metrics.width);
392
+ context.textAlign = wide ? "center" : "start";
393
+ context.fillText(
394
+ cell.text,
395
+ wide ? left + metrics.width : left,
396
+ top + metrics.baseline,
397
+ width,
398
+ );
399
+ context.textAlign = "start";
400
}
401
}
402
}