Skip to content

Measure the terminal's cell on request, and announce a new one - #155

Merged
brainkim merged 1 commit into
mainfrom
measure-cell
Oct 15, 2026
Merged

brainkim merged 1 commit into
mainfrom
measure-cell

Conversation

@brainkim

Copy link
Copy Markdown
Member

For #154: programs drawing proportional content, like images, charts or QR codes on a termdom-cellgrid canvas, need the terminal's real cell size in pixels. TermDOM already asks the terminal for it but kept the answer to itself.

API

  • term.measureCell() asks the terminal for its cell in pixels (XTWINOPS 16) and resolves to {width, height}. It resolves to null when there is nothing to ask (before attach(), after dispose(), output not a terminal) or the terminal doesn't answer. Calls made while a question is out share its answer. It reports the terminal's measurement whatever the cellSize option says, so it gives the real cell under the default unit cell, where it differs from the page's 1×1.
  • cellchange fires on the TermDOM with width and height when the cell is measured at a different size: when the first answer after attach() replaces the size assumed until then, and after a font zoom. The event class is CellChangeEvent, exported with CellChangeEventInit.

The engine's internal 8×16 guess never reaches the public API.

Fix

The cell was asked again after a terminal resize only under cellSize: "auto". Under the default unit cell, a font zoom left images at the size the old cell gave them. It is now asked after every resize.

Tests and docs

  • tests/cell-size.test.ts: the answer, the null cases, shared questions, and cellchange at attach and after a zoom.
  • tests/img.test.ts: a font zoom resizes an image under the unit cell. This test fails on main.
  • The API guide documents measureCell() and cellchange, and the images guide mentions both.

🤖 Generated with Claude Code

An image or a canvas drawing to the cell's true shape needs the cell in
the terminal's pixels, which TermDOM asks the terminal for but kept to
itself (#154). term.measureCell() asks again and resolves to
{width, height}, or null when there is no terminal to ask or it does not
say. Calls made while a question is out share its answer. A cell
measured at another size than before fires a cellchange event on the
TermDOM with the new width and height.

The cell was asked again after a resize only when it sized the page, so
under the default unit cell a font zoom left images at the size the old
cell gave them. It is now asked after every resize.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brainkim
brainkim merged commit 4281c25 into main Oct 15, 2026
8 checks passed
@brainkim
brainkim deleted the measure-cell branch October 15, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant