Repository navigation
Measure the terminal's cell on request, and announce a new one - #155
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For #154: programs drawing proportional content, like images, charts or QR codes on a
termdom-cellgridcanvas, 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 tonullwhen there is nothing to ask (beforeattach(), afterdispose(), 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 thecellSizeoption says, so it gives the real cell under the default unit cell, where it differs from the page's 1×1.cellchangefires on theTermDOMwithwidthandheightwhen the cell is measured at a different size: when the first answer afterattach()replaces the size assumed until then, and after a font zoom. The event class isCellChangeEvent, exported withCellChangeEventInit.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, thenullcases, shared questions, andcellchangeat attach and after a zoom.tests/img.test.ts: a font zoom resizes an image under the unit cell. This test fails onmain.measureCell()andcellchange, and the images guide mentions both.🤖 Generated with Claude Code