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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(terminal): stop cutting off the last column on low-DPI displays
Erik Zwep0c4de52b863c
diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 657eb3e36..3257b8403 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -2834,6 +2834,18 @@ body,-webkit-font-smoothing: auto;}+/* xterm's DOM renderer sets an INLINE `width` (the grid) and `overflow: hidden` on every row. A+ glyph's ink runs a fraction past its advance (Menlo's `m`, `w`), so the last column of a full row+ lost its right edge — measured at DPR 1, canvas zoom 1.38: a 616px row held a 617px span and the+ `m` of "t/m" was cut. Only the HORIZONTAL clip is lifted: the vertical one keeps underlines and+ descenders out of the next row (`clip`, unlike `hidden`, does not turn the other axis's `visible`+ into `auto`). The overhang lands in the host's right padding; `.term-node` still clips, so nothing+ paints outside the node. !important because an inline style beats any selector. */+.xterm-rows > div {+ overflow-x: visible !important;+ overflow-y: clip !important;+}+/* Shared glyph renderer (experimental, `glyphgrid`): a glyph-attached terminal becomes atransparent WINDOW onto the one GPU canvas, which sits between the React Flow background and thenodes (z-index 0 against the renderer's 4 — it cannot simply be raised above them, or adiff --git a/src/renderer/styles.terminal-row-clip.test.ts b/src/renderer/styles.terminal-row-clip.test.tsnew file mode 100644index 000000000..0f4753041--- /dev/null+++ b/src/renderer/styles.terminal-row-clip.test.ts@@ -0,0 +1,42 @@+import { describe, expect, it } from 'vitest'+import { readFileSync } from 'node:fs'+import { join } from 'node:path'++/**+ * xterm's DOM renderer gives every row an INLINE `width` equal to the grid and `overflow: hidden`.+ * A glyph's ink runs a fraction past its advance (Menlo's `m` and `w`), so the last column of every+ * full row lost its right edge — MEASURED on a DPR 1 display at canvas zoom 1.38: a 616px row held a+ * 617px span and the `m` of "t/m" was cut. Letting rows overflow shows the whole glyph; the node+ * root still clips, so nothing can spill past the node.+ */+const CSS = readFileSync(join(__dirname, 'styles.css'), 'utf8').replace(/\r\n/g, '\n')+const XTERM = readFileSync(join(__dirname, '../../node_modules/@xterm/xterm/lib/xterm.js'), 'utf8')++function ruleBody(selector: string): string | null {+ const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')+ const m = new RegExp(`(?:^|\\n)${escaped}\\s*\\{([^}]*)\\}`).exec(CSS)+ return m ? m[1] : null+}++describe('terminal rows do not clip the last column', () => {+ it('lets a DOM-renderer row overflow, overriding the inline style xterm sets', () => {+ const body = ruleBody('.xterm-rows > div')+ expect(body).not.toBeNull()+ // The inline `overflow: hidden` beats any selector, so the override needs !important.+ expect(body).toMatch(/overflow-x:\s*visible\s*!important/)+ // Vertically it must still clip, or underlines and descenders paint into the next row.+ // `clip`, not `hidden`: `hidden` would turn the other axis's `visible` into `auto`.+ expect(body).toMatch(/overflow-y:\s*clip\s*!important/)+ expect(body).not.toMatch(/(^|[^-])overflow:\s*visible/)+ })++ it('still sees xterm setting the inline clip — drop the override if xterm stops doing it', () => {+ expect(XTERM).toContain('style.overflow="hidden"')+ })++ it('keeps the terminal node root clipping, so a row cannot paint outside its node', () => {+ const body = ruleBody('.term-node')+ expect(body).not.toBeNull()+ expect(body).toMatch(/overflow:\s*hidden/)+ })+})diff --git a/src/renderer/terminal/char-size-quantize.test.ts b/src/renderer/terminal/char-size-quantize.test.tsindex 12d842938..ba37f57a1 100644--- a/src/renderer/terminal/char-size-quantize.test.ts+++ b/src/renderer/terminal/char-size-quantize.test.ts@@ -7,6 +7,8 @@ import { quantizeCharSize } from './char-size-quantize'* exactly the fields the helper reaches for — the same seam the guarded-internals style* (`restoreDomRenderer`) tests against. What matters behaviourally:* - measurements land on the device-pixel grid (this is the whole renderer-parity fix);+ * - the grid cell is never NARROWER than the measured glyph (issue: a DPR 1 display rounded+ * Menlo 13's 7.81px down to 7.0, so every glyph overhung its cell and the last column was cut);* - the service is re-measured once at install so the live renderer picks the quantized width;* - a second install is a no-op (mount/adopt call it repeatedly);* - any missing internal fails open with `false` and leaves the strategy untouched.@@ -40,11 +42,40 @@ describe('quantizeCharSize', () => {it('quantizes the measured width to the device-pixel grid (the WebGL floor loses nothing)', () => {const { term, svc } = fakeTerm(8.43, 2)expect(quantizeCharSize(term)).toBe(true)- // floor(8.43 × 2) / 2 = 8.0 — exactly what the WebGL renderer's floor lands on.- expect(svc.width).toBe(8)+ // ceil(8.43 × 2) / 2 = 8.5 — already on the grid, so the WebGL renderer's floor keeps it.+ expect(svc.width).toBe(8.5)+ expect(Math.floor(svc.width * 2) / 2).toBe(svc.width)expect(svc.height).toBe(17) // height untouched})+ it('never makes a cell narrower than its glyph — Menlo 13 at DPR 1 gets 8px, not 7px', () => {+ // MEASURED on a 5120x1440 DPR 1 display: the char-measure element reports 7.8125px for+ // Menlo 13. Rounding down to 7.0 made the DOM renderer pin every glyph with+ // letter-spacing -0.8125px, and the last column's glyph ran past the screen and was cut.+ const { term, svc } = fakeTerm(7.8125, 1)+ quantizeCharSize(term)+ expect(svc.width).toBe(8)+ })++ it('keeps every width on the device grid, at least as wide as measured, and under one device pixel wider', () => {+ for (const dpr of [1, 1.25, 1.5, 2, 3]) {+ for (let raw = 5; raw < 12; raw += 0.0625) {+ const { term, svc } = fakeTerm(raw, dpr)+ quantizeCharSize(term)+ const device = svc.width * dpr+ expect(Math.abs(device - Math.round(device))).toBeLessThan(1e-9)+ expect(svc.width).toBeGreaterThanOrEqual(raw - 1e-3 / dpr)+ expect(svc.width - raw).toBeLessThan(1 / dpr)+ }+ }+ })++ it('does not round a width that is on the grid up by a whole pixel because of float noise', () => {+ const { term, svc } = fakeTerm(7.000000000001, 1)+ quantizeCharSize(term)+ expect(svc.width).toBe(7)+ })+it('re-measures the service once at install, so a live renderer sees the quantized width', () => {const { term, calls } = fakeTerm(8.43, 2)quantizeCharSize(term)@@ -57,16 +88,16 @@ describe('quantizeCharSize', () => {expect(quantizeCharSize(term)).toBe(true)expect(calls.serviceMeasures).toBe(1)svc.measure()- // Still quantized exactly once (a double wrap would floor an already-floored value — same+ // Still quantized exactly once (a double wrap would round an already-rounded value — same// number, but the measure-call count would betray the second wrapper).- expect(svc.width).toBe(8)+ expect(svc.width).toBe(8.5)expect(calls.strategyMeasures).toBe(2)})it('falls back to the window dpr when the core browser service is absent', () => {const { term, svc } = fakeTerm(8.43, undefined)quantizeCharSize(term, { devicePixelRatio: 2 })- expect(svc.width).toBe(8)+ expect(svc.width).toBe(8.5)})it('reads the dpr live at each measure, not once at install', () => {@@ -74,16 +105,16 @@ describe('quantizeCharSize', () => {const { term, svc } = fakeTerm(8.43);(term as unknown as { _core: { _coreBrowserService: { dpr: number } } })._core._coreBrowserService = dprBoxquantizeCharSize(term)- expect(svc.width).toBe(8) // floor(16.86)/2+ expect(svc.width).toBe(8.5) // ceil(16.86)/2dprBox.dpr = 1svc.measure()- expect(svc.width).toBe(8) // floor(8.43)/1 — re-quantized on the new grid+ expect(svc.width).toBe(9) // ceil(8.43)/1 — re-quantized on the new grid})- it('keeps the raw measurement when quantizing would zero the width', () => {- const { term, svc } = fakeTerm(0.4, 1)+ it('passes a zero measurement through (an element that is not rendered yet)', () => {+ const { term, svc } = fakeTerm(0, 1)quantizeCharSize(term)- expect(svc.width).toBe(0.4)+ expect(svc.width).toBe(0)})it('fails open (returns false, touches nothing) when the internals are missing', () => {diff --git a/src/renderer/terminal/char-size-quantize.ts b/src/renderer/terminal/char-size-quantize.tsindex 17f498184..a648cd775 100644--- a/src/renderer/terminal/char-size-quantize.ts+++ b/src/renderer/terminal/char-size-quantize.ts@@ -12,14 +12,23 @@ import type { Terminal } from '@xterm/xterm'* flashes as "the text got wider".** The fix quantizes at the SOURCE both renderers read: `CharSizeService`'s measure strategy is- * wrapped so every measurement lands on the device-pixel grid (`floor(width × dpr) / dpr`).+ * wrapped so every measurement lands on the device-pixel grid (`ceil(width × dpr) / dpr`).* The WebGL floor then loses nothing (it floors an already-integer product) and the DOM renderer* lays out on the identical cell — and `fit`/`proposeDimensions` read the same service, so the* column math stays consistent with what either renderer draws. Height is left alone: both* renderers already ceil it through the same formula.*+ * Rounded UP, never down. The first version floored, and on a DPR 1 display that is a whole pixel:+ * MEASURED on a 5120x1440 DPR 1 monitor, Menlo 13 measures 7.8125px and floored to 7.0, so the DOM+ * renderer pinned every glyph with `letter-spacing: -0.8125px` (text ~10% too tight) and the last+ * column's glyph ran past the edge of the screen element and was cut off ("opnieuw" ending in half a+ * "w"). A cell at least as wide as its glyph cannot overhang. The 1e-3 device-pixel slack keeps a+ * measurement that is already on the grid (7.000000000001) from gaining a whole pixel.+ ** Costs and edges, called out because they are deliberate:- * - A cell can narrow by at most 1/dpr px (≤0.5px on retina) versus the unquantized DOM cell.+ * - A cell can widen by less than 1/dpr px (<0.5px on retina) versus the unquantized DOM cell, so+ * text spreads a little and a terminal fits a few fewer columns at the same width (about 10% for+ * Menlo 13 at DPR 1). The column count is what tmux is told, so nothing is clipped.* - The dpr is read at MEASURE time (live, via the core's browser service with a window* fallback). Moving the window to a display with a different dpr re-quantizes on the next* measure (font/size changes, refresh); until one runs, the widths sit on the old grid —@@ -49,6 +58,9 @@ interface CoreLike {_coreBrowserService?: { dpr?: number }}+/** Device pixels a measurement may sit above the grid and still count as on it (float noise). */+const GRID_SLACK_DEVICE_PX = 1e-3+export function quantizeCharSize(term: Terminal,win: { devicePixelRatio?: number } | undefined = typeof window === 'undefined' ? undefined : window@@ -66,9 +78,8 @@ export function quantizeCharSize(const result = original()const dpr = core?._coreBrowserService?.dpr || win?.devicePixelRatio || 1if (!result || !Number.isFinite(result.width) || !Number.isFinite(dpr) || dpr <= 0) return result- const quantized = Math.floor(result.width * dpr) / dpr- // A sub-device-pixel font would quantize to 0 and invalidate the whole char size — keep- // the raw measurement there (the renderers disagree again, but they draw).+ const quantized = Math.ceil(result.width * dpr - GRID_SLACK_DEVICE_PX) / dpr+ // A zero measurement (element not rendered yet) stays zero — xterm treats it as "unknown".if (quantized <= 0) return resultreturn { width: quantized, height: result.height }}