terminal/osc: accept iTerm2 OSC 1337 ReportCellSize query#379
Merged
Conversation
iTerm2 emitters like imgcat can query the cell pixel size with `OSC 1337;ReportCellSize ST`. The terminal replies with `OSC 1337;ReportCellSize=H;W;1.0 ST` carrying the cell dimensions in backing pixels (scale=1.0 so clients computing H*scale get the value they need without DPR plumbing). The dispatch reuses the existing size-report Action so that libghostty-vt embedders implementing reportSize get the response for free, mirroring csi_21_t which is similarly OSC-driven. Trailing `=` with an empty value is accepted defensively to match the FileEnd path's tolerance for naive `key=value` emitters; any `=non-empty` form is rejected because it would collide with the response shape.
Add the matching GHOSTTY_SIZE_REPORT_ITERM2_REPORT_CELL_SIZE entry to the C header so the libghostty-vt ABI mirrors the Zig enum, and tighten a few comments to ground them in the actual mechanism (key=value split producing an empty value, backing pixels instead of "logical pixels on retina").
This was referenced May 19, 2026
deblasis
added a commit
that referenced
this pull request
May 21, 2026
iTerm2 emitters like imgcat can query the cell pixel size with `OSC 1337;ReportCellSize ST`. The terminal replies with `OSC 1337;ReportCellSize=H;W;1.0 ST` carrying the cell dimensions in backing pixels (scale=1.0 so clients computing H*scale get the value they need without DPR plumbing). The dispatch reuses the existing size-report Action so that libghostty-vt embedders implementing reportSize get the response for free, mirroring csi_21_t which is similarly OSC-driven. The libghostty-vt C ABI gains a matching GHOSTTY_SIZE_REPORT_ITERM2_REPORT_CELL_SIZE entry. Trailing `=` with an empty value is accepted defensively because the upstream key=value split produces an empty value for such input; any `=non-empty` form is rejected because it would collide with the response shape.
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.
Summary
Accept iTerm2's
OSC 1337;ReportCellSizebare-key query and reply with the cell pixel size on the pty. Sixth PR in the iTerm2 OSC 1337 series (after #375 #376 #377 #378), and the smallest by design.Emitters like
imgcatuse this to compute image-cell scaling. With the prior PRs we accept and render inline images; this PR closes the loop so clients can ask the terminal "how big is a cell?" before sending an image.Wire format
\x1b]1337;ReportCellSize\x1b\(bare key)\x1b]1337;ReportCellSize={cell_height};{cell_width};1.0\x1b\The trailing
1.0is iTerm2's HiDPI scale field. Ghostty reports cell metrics already in backing pixels, soscale=1.0lets clients computeH * scale = backing_pixelswithout us threading device-pixel ratio through the size-report pipeline. Clients that parse the legacy two-field form ignore the trailing scale.Architecture
Reuses the existing
size_report.Actiondispatch:iterm2_report_cell_sizevariant oncsi.SizeReportStyle(alongsidecsi_21_twhich is similarly OSC-driven, so this is not a new pattern)iterm2_report_cell_sizevariant onsize_report.Style(encoder-side enum) and an encoder branchparsers/iterm2.zigemittingCommand.iterm2_report_cell_size(void).size_reportwith the new stylesendSizeReport(termio) andreportSize(libghostty-vt embedders) both pick up the new variant through their existing switchesResult: libghostty-vt embedders that implement
effects.sizeget the ReportCellSize response without any C-side or apprt-side work.Parser permissiveness
ReportCellSize-> emit queryReportCellSize=-> emit query (defensive, matchesFileEnd=precedent)ReportCellSize=non-empty-> reject (would collide with the response shape)Tests
=empty value accepted,=non-emptyrejectedTest plan
zig build testpasses on Windowszig build testpasses on macOS (via SSH bundle)imgcatonce we have a Wintty.exe build