Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(glyphgrid): render underlines — the SGR attribute and the hovered link

enesb66ddf3df41e
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
index 5f60136a7..399303269 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -358,6 +358,18 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
be untouched — if plain Latin text looks smaller or unevenly sized after this, the tolerance
is misfiring and that is a **release blocker**.
+- [ ] **2.19 Underline — the attribute AND the hovered link.** Until 2026-08-05 shared mode drew no
+ underline at all: the feed wrote the flag and nothing read it. Two things to check, because
+ they are two sources of one mechanism.
+ **The attribute:** `printf '\033[4municn underlined text\033[0m\n'` — one continuous rule under
+ the whole run, spaces included (a rule that dashes at word gaps means the blank cells are
+ short-circuiting again), joining cleanly across cell boundaries with no gaps, and the same
+ weight as GPU mode's.
+ **The link:** hover a URL with ⌘ held (an agent CLI's login URL is the reported case) — the
+ underline appears under the WHOLE link, including its last character, and disappears when the
+ pointer leaves. Move the pointer between two links on one line and confirm the old one clears.
+ A link that wraps across rows is underlined on every row it covers.
+
## 3. Interactions
- [ ] **3.1 Wheel scrolls tmux history.** Wheel over a terminal scrolls tmux's own scrollback, the
diff --git a/src/renderer/glyphgrid/addon.ts b/src/renderer/glyphgrid/addon.ts
index 0851ceaf8..47f4f3049 100644
--- a/src/renderer/glyphgrid/addon.ts
+++ b/src/renderer/glyphgrid/addon.ts
@@ -103,6 +103,28 @@ export interface TermInternals {
decorations?: DecorationReader
onDecorationRegistered?(cb: () => void): { dispose(): void }
onDecorationRemoved?(cb: () => void): { dispose(): void }
+ /**
+ * The link the pointer is currently over, in VIEWPORT cell coordinates, or null.
+ *
+ * xterm reports a hovered link as a range and its own render layers answer by underlining it —
+ * the affordance that says ⌘-click will open this. Replacing xterm's renderer removes those
+ * layers, so this renderer has to draw it, or every link looks inert (reported 2026-08-05).
+ *
+ * OPTIONAL like the decorations, and for the same reason: a build whose linkifier is missing or
+ * reshaped degrades to "no link underlines", never to a refused attach.
+ */
+ linkUnderline?: LinkUnderline
+}
+
+/**
+ * A hovered link's extent, in VIEWPORT cell coordinates — the shape xterm's linkifier fires
+ * (`y` already has `ydisp` subtracted). Inclusive on both ends, as xterm reports it.
+ */
+export interface LinkUnderline {
+ /** The current range, or null when nothing is hovered. Read once per pack. */
+ current(): { x1: number; y1: number; x2: number; y2: number } | null
+ /** Fires when the hovered range changes, so the shell can repaint the rows it covers. */
+ onChange(cb: () => void): { dispose(): void }
}
/** The exact shape of xterm's `IRenderer.dimensions`. RenderService reads it straight off the
@@ -251,6 +273,16 @@ export class GlyphGridRendererAddonCore {
const onRemoved = internals.onDecorationRemoved
if (onRegistered) this.decorationSubs.push(onRegistered(() => this.handleDecorationChange()))
if (onRemoved) this.decorationSubs.push(onRemoved(() => this.handleDecorationChange()))
+ // The hovered link changes with the POINTER, not with the buffer, so nothing else would ever
+ // repaint those rows: without this the underline appears only when some unrelated output
+ // happens to redraw the line under the cursor. Shares the decoration bag — same lifetime, same
+ // teardown, and one fewer thing for `dispose` to remember.
+ const onLink = internals.linkUnderline?.onChange
+ if (onLink) {
+ this.decorationSubs.push(
+ internals.linkUnderline!.onChange(() => this.handleDecorationChange())
+ )
+ }
// LAST, and after the subscriptions, for the same reason they go last: this publishes the addon
// into a CANVAS-LEVEL singleton, and a construction that threw afterwards would leave it there
// with nobody holding an addon to release it. Seeded rather than waited for, because a mode
@@ -627,6 +659,9 @@ export class GlyphGridRendererAddonCore {
atlas: this.atlas,
theme,
selection: this.selectionOnRow(this.absRow),
+ // VIEWPORT row, not the absolute one: xterm's linkifier already subtracted `ydisp` when it
+ // fired, so the range is in the coordinates the user is currently looking at.
+ linkUnderline: this.linkOnRow(row),
cursorCol: row === cursorRow ? cursorCol : -1,
cursorShape,
// Only the SELECTION colour depends on this (an unfocused terminal's band is quieter — L3);
@@ -690,6 +725,23 @@ export class GlyphGridRendererAddonCore {
return endCol > startCol ? [startCol, endCol] : null
}
+ /**
+ * The hovered link's column span on this VIEWPORT row, `[startCol, endColExclusive)`, or null.
+ *
+ * xterm's range is INCLUSIVE at both ends and can span rows; a middle row is covered edge to
+ * edge. The `+ 1` on the end column is that inclusive→exclusive conversion, and forgetting it
+ * leaves the link's last character un-underlined — a one-cell gap that reads as a rendering bug
+ * rather than as an off-by-one.
+ */
+ private linkOnRow(row: number): readonly [number, number] | null {
+ const link = this.internals.linkUnderline?.current()
+ if (!link) return null
+ if (row < link.y1 || row > link.y2) return null
+ const startCol = row === link.y1 ? link.x1 : 0
+ const endCol = row === link.y2 ? link.x2 + 1 : this.cols
+ return endCol > startCol ? [Math.max(0, startCol), Math.min(this.cols, endCol)] : null
+ }
+
/** Which VIEWPORT rows the current selection covers — the repaint unit, clamped to the grid. */
private selectionRowRange(): RowRange {
const top = this.selTop
diff --git a/src/renderer/glyphgrid/atlas.test.ts b/src/renderer/glyphgrid/atlas.test.ts
index 6f1377ce5..3265698fe 100644
--- a/src/renderer/glyphgrid/atlas.test.ts
+++ b/src/renderer/glyphgrid/atlas.test.ts
@@ -545,10 +545,10 @@ describe('GlyphAtlas', () => {
atlas.glyphFor(0x20, false, false, FG, BG) // the blank slot is never an allocation
atlas.glyphFor(0x78, false, false, FG, BG, 'wide-right') // …and so is the other half
expect(seen).toEqual([
- { slot: 1, code: 0x78, bold: false, italic: false, x: 16, y: 2, fg: FG, bg: BG, part: 'whole' as const },
- { slot: 2, code: 0x78, bold: true, italic: false, x: 30, y: 2, fg: FG, bg: BG, part: 'whole' as const },
- { slot: 3, code: 0x78, bold: false, italic: false, x: 44, y: 2, fg: FG + 1, bg: BG, part: 'whole' as const },
- { slot: 4, code: 0x78, bold: false, italic: false, x: 58, y: 2, fg: FG, bg: BG, part: 'wide-right' as const }
+ { slot: 1, code: 0x78, bold: false, italic: false, x: 16, y: 2, fg: FG, bg: BG, part: 'whole' as const, underline: false },
+ { slot: 2, code: 0x78, bold: true, italic: false, x: 30, y: 2, fg: FG, bg: BG, part: 'whole' as const, underline: false },
+ { slot: 3, code: 0x78, bold: false, italic: false, x: 44, y: 2, fg: FG + 1, bg: BG, part: 'whole' as const, underline: false },
+ { slot: 4, code: 0x78, bold: false, italic: false, x: 58, y: 2, fg: FG, bg: BG, part: 'wide-right' as const, underline: false }
])
})
diff --git a/src/renderer/glyphgrid/atlas.ts b/src/renderer/glyphgrid/atlas.ts
index a84650532..0175575fc 100644
--- a/src/renderer/glyphgrid/atlas.ts
+++ b/src/renderer/glyphgrid/atlas.ts
@@ -30,7 +30,8 @@ export interface GlyphRasterizer {
y: number,
fg: number,
bg: number,
- part?: GlyphPart
+ part?: GlyphPart,
+ underline?: boolean
): void
/** Blank the whole page. Called by `GlyphAtlas.reset()` and by nothing else: the bookkeeping and
* the pixels have to be emptied in the same breath or a stale slot keeps its old ink. */
@@ -145,6 +146,8 @@ export interface GlyphSlotAllocation {
/** Which part of its character this slot holds (see `GlyphPart`). 'whole' for every ordinary
* glyph, so a dump that never shows a wide-* means nothing double-width was drawn. */
part: GlyphPart
+ /** Whether this slot carries an underline — a cell attribute, or a hovered link. */
+ underline: boolean
}
/** What `onReset` hands back. A plain disposable rather than an unsubscribe function so the call
@@ -360,9 +363,13 @@ export class GlyphAtlas {
italic: boolean,
fg: number,
bg: number,
- part: GlyphPart = 'whole'
+ part: GlyphPart = 'whole',
+ underline = false
): number {
- if (code === 0x20 || code === 0) return 0
+ // A blank cell has nothing to rasterize — UNLESS it is underlined. An underlined run is text
+ // and spaces together (`\e[4munder line\e[0m`), and returning the blank slot for the spaces
+ // would break the rule into dashes at every word gap.
+ if ((code === 0x20 || code === 0) && !underline) return 0
// `>>> 0` on both lanes: `0xff << 24` is NEGATIVE in JS (packColor carries the same note), so
// one colour can arrive as -16777216 from an arithmetic path and as 4278190080 off a cell
// lane. Keying the two spellings separately would put identical pixels in two slots — wasted
@@ -371,7 +378,7 @@ export class GlyphAtlas {
// `part` is IN the key: the two halves of one character are different pixels, and keying them
// together would hand the follower the lead's slot and paint the left half twice. 'whole' and
// 'wide-left' differ too — same drawing, different entitlement, so a different shrink.
- const key = `${code}|${bold ? 1 : 0}${italic ? 1 : 0}|${fg >>> 0}|${bg >>> 0}|${part}`
+ const key = `${code}|${bold ? 1 : 0}${italic ? 1 : 0}${underline ? 1 : 0}|${fg >>> 0}|${bg >>> 0}|${part}`
const hit = this.slots.get(key)
if (hit !== undefined) return hit
if (this.nextSlot >= this.capacity) {
@@ -392,14 +399,14 @@ export class GlyphAtlas {
}
const slot = this.nextSlot++
const { x, y } = this.cellXY(slot)
- this.rasterizer.draw(code, bold, italic, x, y, fg, bg, part)
+ this.rasterizer.draw(code, bold, italic, x, y, fg, bg, part, underline)
this.slots.set(key, slot)
this.dirtyFlag = true
// LAST, and guarded: the tap is a debug aid, so a throwing callback must cost a log line, not
// the glyph — everything above is already committed by the time it runs.
if (this.onAllocate) {
try {
- this.onAllocate({ slot, code, bold, italic, x, y, fg, bg, part })
+ this.onAllocate({ slot, code, bold, italic, x, y, fg, bg, part, underline })
} catch {
/* a debug tap never breaks a frame */
}
diff --git a/src/renderer/glyphgrid/feed.test.ts b/src/renderer/glyphgrid/feed.test.ts
index 169bae117..fa6fa6105 100644
--- a/src/renderer/glyphgrid/feed.test.ts
+++ b/src/renderer/glyphgrid/feed.test.ts
@@ -27,6 +27,7 @@ function fakeAtlas(): Pick<GlyphAtlas, 'glyphFor'> & {
calls: Array<[number, boolean, boolean]>
colors: Array<[number, number]>
parts: GlyphPart[]
+ underlines: boolean[]
} {
const calls: Array<[number, boolean, boolean]> = []
const colors: Array<[number, number]> = []
@@ -35,21 +36,25 @@ function fakeAtlas(): Pick<GlyphAtlas, 'glyphFor'> & {
// rendering whole and rendering as its left fragment. Kept out of `calls` so the many
// assertions that pin `calls` verbatim stay about what they were written for.
const parts: GlyphPart[] = []
+ const underlines: boolean[] = []
return {
calls,
colors,
parts,
+ underlines,
glyphFor(
code: number,
bold: boolean,
italic: boolean,
fg: number,
bg: number,
- part: GlyphPart = 'whole'
+ part: GlyphPart = 'whole',
+ underline = false
): number {
calls.push([code, bold, italic])
colors.push([fg, bg])
parts.push(part)
+ underlines.push(underline)
return 900 + calls.length
}
}
@@ -128,6 +133,7 @@ function pack(
| 'cursorShape'
| 'focused'
| 'atlas'
+ | 'linkUnderline'
| 'decorations'
| 'bufferRow'
>
@@ -141,6 +147,7 @@ function pack(
atlas,
theme: THEME,
selection: o.selection ?? null,
+ linkUnderline: o.linkUnderline ?? null,
cursorCol: o.cursorCol ?? -1,
cursorShape: o.cursorShape,
focused: o.focused,
@@ -756,3 +763,39 @@ describe('the blank-cell probe', () => {
}
})
})
+
+/**
+ * The 2026-08-05 report was a hovered link with no underline. Its range reaches the feed the same
+ * way a selection does — a column span on this row — and sets the SAME flag a cell's own SGR 4
+ * attribute sets, so the two sources can never disagree about how an underline looks.
+ */
+describe('packViewportRow — the hovered link underline', () => {
+ it('underlines exactly the columns in the span', () => {
+ const cells = [makeCell({ code: 0x61 }), makeCell({ code: 0x62 }), makeCell({ code: 0x63 })]
+ const { out } = pack(cells, { linkUnderline: [1, 3] })
+ expect(readCell(out, 0).flags & FLAG_UNDERLINE).toBe(0)
+ expect(readCell(out, 1).flags & FLAG_UNDERLINE).toBe(FLAG_UNDERLINE)
+ expect(readCell(out, 2).flags & FLAG_UNDERLINE).toBe(FLAG_UNDERLINE)
+ })
+
+ it('asks the atlas for the UNDERLINED variant, not just the flag', () => {
+ // The flag alone changes nothing on screen: the underline is baked into the slot, so a lane
+ // that carries the flag while the slot was rasterized without one renders bare.
+ const { atlas } = pack([makeCell({ code: 0x61 })], { linkUnderline: [0, 1] })
+ expect(atlas.underlines).toEqual([true])
+ })
+
+ it('underlines a SPACE inside the span — a rule must not dash at word gaps', () => {
+ // A blank normally short-circuits to the blank slot; an underline is the one thing that makes
+ // it carry ink. A URL with a space, or any `\e[4m` run, breaks visibly without this.
+ const { out, atlas } = pack([makeCell({ code: 0x20 })], { linkUnderline: [0, 1] })
+ expect(readCell(out, 0).glyph).not.toBe(0)
+ expect(atlas.underlines).toEqual([true])
+ })
+
+ it('never turns an existing underline OFF', () => {
+ // Hovering a link over text that is already underlined must add, not replace.
+ const { out } = pack([makeCell({ code: 0x61, underline: true })], { linkUnderline: null })
+ expect(readCell(out, 0).flags & FLAG_UNDERLINE).toBe(FLAG_UNDERLINE)
+ })
+})
diff --git a/src/renderer/glyphgrid/feed.ts b/src/renderer/glyphgrid/feed.ts
index 0cc338ad5..9d48e2c85 100644
--- a/src/renderer/glyphgrid/feed.ts
+++ b/src/renderer/glyphgrid/feed.ts
@@ -60,6 +60,19 @@ export interface RowFeedOpts {
theme: ThemeLanes
/** Selection span on THIS viewport row, in columns [startCol, endColExclusive), or null. */
selection: readonly [number, number] | null
+ /**
+ * The HOVERED LINK's column span on THIS row, `[startCol, endColExclusive)`, or null.
+ *
+ * Separate from `decorations` because it is not a colour: xterm's linkifier reports a hovered
+ * link as a range and its own render layers answer by drawing an underline, which is the
+ * affordance that tells you ⌘-click will open it. A renderer that replaces xterm's own therefore
+ * has to draw it too, or the link is silently unclickable-looking (reported 2026-08-05 — the
+ * `claude /login` URL underlined in GPU mode and bare in shared).
+ *
+ * It sets the SAME `FLAG_UNDERLINE` a cell's own SGR 4 attribute sets, so the two are one
+ * mechanism with two sources and can never disagree about how an underline looks.
+ */
+ linkUnderline?: readonly [number, number] | null
/** The cursor's column on THIS row, or -1. */
cursorCol: number
/** The shape the cursor at `cursorCol` takes. Only `block` is expressible as a cell rewrite —
@@ -133,6 +146,19 @@ function isRenderableCode(code: number): boolean {
)
}
+/**
+ * Is this a BLANK the atlas can still be asked to paint — i.e. a space, or the 0 an empty cell
+ * reports?
+ *
+ * Only reached for an UNDERLINED cell (see the request site). A blank normally short-circuits to
+ * the blank slot, and must keep doing so: it is the most common cell on the canvas, and a slot per
+ * space-with-these-colours would burn the page for pixels that are pure background. An underline is
+ * the one thing that makes a blank cell carry ink.
+ */
+function drawableBlank(code: number): boolean {
+ return code === 0x20 || code === 0
+}
+
/** Which code point this cell should draw.
*
* `getCode()` alone is WRONG for a combining sequence: xterm stores the whole sequence in the
@@ -280,6 +306,8 @@ export function packViewportRow(
const { cols, atlas, theme, selection, cursorCol } = opts
const selStart = selection ? selection[0] : -1
const selEnd = selection ? selection[1] : -1
+ const linkStart = opts.linkUnderline ? opts.linkUnderline[0] : -1
+ const linkEnd = opts.linkUnderline ? opts.linkUnderline[1] : -1
// Only a block is a cell rewrite; every other shape is the overlay pass's business (cursor.ts).
const blockCursor = (opts.cursorShape ?? 'block') === 'block'
// Resolved ONCE per row, and only for a row that HAS a selection: the blend is four roundings, and
@@ -414,6 +442,9 @@ export function packViewportRow(
}
}
+ // The hovered link's underline, ORed in rather than assigned: a link drawn over text that is
+ // ALREADY underlined stays underlined, and hovering it must not be able to turn one off.
+ if (col >= linkStart && col < linkEnd) flags |= FLAG_UNDERLINE
if (col >= selStart && col < selEnd) {
bg = selectionBg
flags |= FLAG_SELECTED
@@ -425,7 +456,16 @@ export function packViewportRow(
}
// fg/bg are FINAL here — this is the only place the atlas may be asked, see the doc comment.
- const glyph = isRenderableCode(code) ? atlas.glyphFor(code, bold, italic, fg, bg, part) : 0
+ //
+ // An UNDERLINED cell is asked for even when its code is not renderable on its own. The rule is
+ // an underline runs UNDER THE WHOLE RUN, spaces included (`\e[4munder line\e[0m`, and every
+ // hovered URL with a space in it): skipping the blanks would break one rule into dashes at each
+ // word gap. `isRenderableCode` still guards the CRASH cases — a lone surrogate or a control
+ // code is refused whatever its underline says — so this only widens it to the blanks the atlas
+ // knows how to answer.
+ const underlined = (flags & FLAG_UNDERLINE) !== 0
+ const wantsSlot = isRenderableCode(code) || (underlined && drawableBlank(code))
+ const glyph = wantsSlot ? atlas.glyphFor(code, bold, italic, fg, bg, part, underlined) : 0
// A cell that HOLDS something and still draws nothing is the defect under investigation. A
// space is excluded because that is the correct answer for it, not a loss.
if (blankProbe && glyph === 0 && probeChars !== '' && probeChars !== ' ') {
diff --git a/src/renderer/glyphgrid/raster.test.ts b/src/renderer/glyphgrid/raster.test.ts
index 9d697b41d..529a705bc 100644
--- a/src/renderer/glyphgrid/raster.test.ts
+++ b/src/renderer/glyphgrid/raster.test.ts
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it } from 'vitest'
import { GlyphAtlas, GUTTER_PX } from './atlas'
import { packColor } from './cells'
-import { createCanvasRasterizer, shrinkToFit } from './raster'
+import { createCanvasRasterizer, shrinkToFit, underlineThickness } from './raster'
/**
* These tests pin the three rects a colored draw uses, because the whole mip story rests on them:
@@ -966,6 +966,53 @@ describe('createCanvasRasterizer', () => {
* floor, a platform that reports no ink box), and each of those is one number rather than a
* rendering.
*/
+describe('underline', () => {
+ /**
+ * Reported 2026-08-05: a hovered link showed no underline in shared mode while GPU mode drew one.
+ * The cause was broader than links — `FLAG_UNDERLINE` was written by the feed and read by nobody,
+ * so NO underline rendered at all, including a plain `\e[4m` run.
+ */
+ it('draws a rule at the bottom of the cell, spanning the WHOLE-TEXEL box', () => {
+ const stub = stubCanvas()
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x41, false, false, INK_X, INK_Y, FG, BG, 'whole', true)
+ const rule = stub.ops.filter((o) => o.kind === 'fillRect').at(-1)!
+ // Full box width, not the fractional cell: consecutive underlined cells have to JOIN, and a
+ // rule that stopped inside the partial edge texel would dash at every cell boundary.
+ expect(rule.args[0]).toBe(INK_X)
+ expect(rule.args[2]).toBe(COLS_W)
+ // Bottom of the cell, in the FOREGROUND colour.
+ expect(rule.args[1]).toBe(INK_Y + COLS_H - 1)
+ expect(rule.fill).toBe(FG_CSS)
+ })
+
+ it('draws NOTHING extra when the cell is not underlined', () => {
+ const plain = stubCanvas()
+ active = plain
+ createCanvasRasterizer(FONT, 256)!.draw(0x41, false, false, INK_X, INK_Y, FG, BG)
+ const underlined = stubCanvas()
+ active = underlined
+ createCanvasRasterizer(FONT, 256)!.draw(0x41, false, false, INK_X, INK_Y, FG, BG, 'whole', true)
+ expect(underlined.ops.length).toBeGreaterThan(plain.ops.length)
+ })
+})
+
+describe('underlineThickness', () => {
+ it("follows xterm's own rule, so the weight matches the renderer beside it", () => {
+ expect(underlineThickness(15)).toBe(1)
+ expect(underlineThickness(30)).toBe(2)
+ expect(underlineThickness(45)).toBe(3)
+ })
+
+ it('never rounds away to nothing — an absent underline IS the bug', () => {
+ expect(underlineThickness(8)).toBe(1)
+ expect(underlineThickness(0)).toBe(1)
+ expect(underlineThickness(NaN)).toBe(1)
+ })
+})
+
describe('shrinkToFit', () => {
const metrics = (left: number, right: number): TextMetrics =>
({ actualBoundingBoxLeft: left, actualBoundingBoxRight: right }) as TextMetrics
diff --git a/src/renderer/glyphgrid/raster.ts b/src/renderer/glyphgrid/raster.ts
index d903ff6de..ec45c95d0 100644
--- a/src/renderer/glyphgrid/raster.ts
+++ b/src/renderer/glyphgrid/raster.ts
@@ -30,6 +30,11 @@ export interface RasterFont {
* `GlyphAtlas.glyphFor` applies to its KEY, kept here so the two can never disagree about what
* "the same colour" means.
*/
+function cssColor(packed: number): string {
+ const { r, g, b } = unpackColor(packed >>> 0)
+ return `rgb(${r},${g},${b})`
+}
+
/**
* How much a glyph's ink may exceed what its character is entitled to before it is shrunk.
*
@@ -76,9 +81,18 @@ export function shrinkToFit(metrics: TextMetrics, allowance: number): number {
return Math.max(MIN_INK_FIT_SCALE, allowance / inkW)
}
-function cssColor(packed: number): string {
- const { r, g, b } = unpackColor(packed >>> 0)
- return `rgb(${r},${g},${b})`
+/**
+ * How thick an underline is, in device pixels, for a font of this size.
+ *
+ * xterm's own rule (`Math.max(1, floor(fontSize / 15))`), adopted rather than invented so an
+ * underline in shared mode is the same weight as the one beside it in GPU mode. The floor of 1 is
+ * the load-bearing half: the atlas is rasterized at the DEVICE cell, and a sub-pixel rule would
+ * round away to nothing at small sizes — an underline that is simply absent, which is the defect
+ * this whole path exists to fix.
+ */
+export function underlineThickness(fontSizePx: number): number {
+ if (!Number.isFinite(fontSizePx) || fontSizePx <= 0) return 1
+ return Math.max(1, Math.floor(fontSizePx / 15))
}
/**
@@ -334,7 +348,7 @@ export function createCanvasRasterizer(
/** `x, y` is the INK origin the atlas hands us — already one gutter inside the pitch cell on
* each axis (`GlyphAtlas.cellXY`) — and `fg`/`bg` are the FINAL packed colour lanes for this
* slot. Two DIFFERENT rects are involved; see the header's invariants 3 and 4. */
- draw(code, bold, italic, x, y, fg, bg, part = 'whole') {
+ draw(code, bold, italic, x, y, fg, bg, part = 'whole', underline = false) {
// The glyph's own origin inside this slot. 'wide-right' is the RIGHT half of a double-width
// character (see `GlyphAtlas.glyphFor`): the character is drawn one cell FURTHER LEFT, so the
// window this slot's clip keeps is its second cell instead of its first. Everything else
@@ -492,6 +506,34 @@ export function createCanvasRasterizer(
}
}
ctx.restore()
+ // 2b. THE UNDERLINE, if this cell carries one.
+ //
+ // Drawn HERE, after the ink clip is dropped, and with its own WHOLE-TEXEL clip — the same
+ // box the geometry branch uses. It is geometry WE generate, not something the face drew,
+ // so it wants the box for the same reason box-drawing does: a fractional cell's outermost
+ // texel is only partly covered, and a rule that stops inside it leaves a gap at every cell
+ // boundary. Spanning the box makes consecutive underlined cells join into one continuous
+ // line, which is the whole point of an underline under a run of text.
+ //
+ // It is BAKED INTO THE SLOT rather than drawn as an overlay pass, because an underline is
+ // part of how a cell looks: the atlas is already keyed by colour and style, `underline` is
+ // one more key lane, and the shader needs no new concept at all. The cost is a second slot
+ // for text that appears both underlined and not — which is what a hovered link is, and it
+ // is bounded by the same reset the colour keys already live with.
+ //
+ // Position and thickness follow xterm's own: a line at the BOTTOM of the cell (descenders
+ // cross it, exactly as in every terminal), one device pixel scaled with the font so it
+ // stays visible at large sizes and never disappears at small ones.
+ if (underline) {
+ ctx.save()
+ ctx.beginPath()
+ ctx.rect(x, y, colsW, colsH)
+ ctx.clip()
+ ctx.fillStyle = cssColor(fg)
+ const thickness = underlineThickness(font.sizePx)
+ ctx.fillRect(x, y + colsH - thickness, colsW, thickness)
+ ctx.restore()
+ }
// 3. THE EDGE EXTENSION — clamp-to-edge padding, the standard atlas technique. Replicate the
// cell's outermost texel row/column outward into the gutter, so the gutter continues the
// cell instead of falling back to flat background.
diff --git a/src/renderer/terminal/glyphgrid-attach.ts b/src/renderer/terminal/glyphgrid-attach.ts
index e22b10ab9..f6302eace 100644
--- a/src/renderer/terminal/glyphgrid-attach.ts
+++ b/src/renderer/terminal/glyphgrid-attach.ts
@@ -20,6 +20,7 @@ import {
import {
GlyphGridRendererAddonCore,
type DeviceMetrics,
+ type LinkUnderline,
type TermInternals
} from '../glyphgrid/addon'
import type { GlyphAtlas } from '../glyphgrid/atlas'
@@ -66,6 +67,84 @@ interface XtermDecorationService {
onDecorationRegistered(cb: () => void): { dispose(): void }
onDecorationRemoved(cb: () => void): { dispose(): void }
}
+/** xterm's `linkifier` — the source of the hovered-link underline. OPTIONAL, see `linkUnderlineOf`. */
+interface XtermLinkifier {
+ onShowLinkUnderline(cb: (e: LinkUnderlineEvent) => void): { dispose(): void }
+ onHideLinkUnderline(cb: (e: LinkUnderlineEvent) => void): { dispose(): void }
+}
+/** What xterm fires: the hovered range in VIEWPORT cell coordinates (`ydisp` already subtracted),
+ * inclusive at both ends. */
+interface LinkUnderlineEvent {
+ x1: number
+ y1: number
+ x2: number
+ y2: number
+}
+/**
+ * The hovered-link underline, read off xterm's own linkifier.
+ *
+ * xterm's DOM and WebGL renderers each carry a link render LAYER that subscribes to these two
+ * events and draws the underline under a hovered link. Replacing the renderer removes those layers
+ * with it, which is why a link in shared mode had no underline at all while GPU mode showed one
+ * (reported 2026-08-05, on the `claude /login` URL). This puts the same information back, and the
+ * addon renders it through the ordinary underline path rather than a special case.
+ *
+ * OPTIONAL exactly like `decorationsOf`: a build whose linkifier is missing or reshaped hands back
+ * null, `linkUnderline` stays undefined, and the terminal simply never underlines a hovered link —
+ * which is where shared mode already was, so the degrade costs nothing that was working.
+ *
+ * The range is kept HERE rather than in the addon because the addon must not hold xterm objects:
+ * this is the same thin-shell rule the decoration reader follows.
+ */
+function linkUnderlineOf(core: XtermCore): { linkUnderline: LinkUnderline } | null {
+ const lk = core.linkifier
+ if (!lk || typeof lk.onShowLinkUnderline !== 'function') return null
+ if (typeof lk.onHideLinkUnderline !== 'function') return null
+ const linkifier = lk as XtermLinkifier
+
+ let current: LinkUnderlineEvent | null = null
+ const listeners = new Set<() => void>()
+ const notify = (): void => {
+ for (const cb of [...listeners]) {
+ try {
+ cb()
+ } catch {
+ /* one bad listener must not cost the others their repaint */
+ }
+ }
+ }
+ // HIDE clears unconditionally rather than comparing ranges: xterm fires hide for the link that
+ // is leaving, and a stale range left standing would underline text the pointer is no longer on.
+ const subs = [
+ linkifier.onShowLinkUnderline((e) => {
+ current = { x1: e.x1, y1: e.y1, x2: e.x2, y2: e.y2 }
+ notify()
+ }),
+ linkifier.onHideLinkUnderline(() => {
+ if (!current) return
+ current = null
+ notify()
+ })
+ ]
+
+ return {
+ linkUnderline: {
+ current: () => current,
+ onChange: (cb: () => void) => {
+ listeners.add(cb)
+ return {
+ dispose: () => {
+ listeners.delete(cb)
+ // The xterm subscriptions themselves live for the terminal's life: they are cheap, and
+ // dropping them on the last listener would leave a re-attached renderer blind.
+ void subs
+ }
+ }
+ }
+ }
+ }
+}
+
/** The private members of xterm 5.5 we depend on. Names verified against the shipped bundle. */
interface XtermCore {
_renderService: { setRenderer(r: unknown): void; handleResize(cols: number, rows: number): void }
@@ -82,6 +161,7 @@ interface XtermCore {
* so an xterm that dropped or reshaped this service must cost the user their highlights, not
* their renderer. `coreOf` never checks it; `decorationsOf` shape-checks it and answers null. */
_decorationService?: Partial<XtermDecorationService>
+ linkifier?: Partial<XtermLinkifier>
}
/** Every internal read in this module starts here. Presence-checked rather than cast, so a bumped
@@ -340,7 +420,10 @@ export function attachGlyphGrid(
},
// Spread, so a terminal with no usable decoration service leaves all three members undefined —
// the addon's "this terminal has no highlights" case.
- ...(decorationsOf(core) ?? {})
+ ...(decorationsOf(core) ?? {}),
+ // Same shape for the linkifier: absent leaves `linkUnderline` undefined and the addon simply
+ // never underlines a hovered link, which is where shared mode already was.
+ ...(linkUnderlineOf(core) ?? {})
}
let addon: GlyphGridRendererAddonCore