Skip to content

terminal/osc: accept iTerm2 OSC 1337 ReportCellSize query#379

Merged
deblasis merged 2 commits into
windowsfrom
kitten-into-wintty/iterm2-report-cell-size
May 19, 2026
Merged

terminal/osc: accept iTerm2 OSC 1337 ReportCellSize query#379
deblasis merged 2 commits into
windowsfrom
kitten-into-wintty/iterm2-report-cell-size

Conversation

@deblasis
Copy link
Copy Markdown
Owner

Summary

Accept iTerm2's OSC 1337;ReportCellSize bare-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 imgcat use 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

  • Request: \x1b]1337;ReportCellSize\x1b\ (bare key)
  • Response: \x1b]1337;ReportCellSize={cell_height};{cell_width};1.0\x1b\

The trailing 1.0 is iTerm2's HiDPI scale field. Ghostty reports cell metrics already in backing pixels, so scale=1.0 lets clients compute H * scale = backing_pixels without 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.Action dispatch:

  • New iterm2_report_cell_size variant on csi.SizeReportStyle (alongside csi_21_t which is similarly OSC-driven, so this is not a new pattern)
  • New iterm2_report_cell_size variant on size_report.Style (encoder-side enum) and an encoder branch
  • Parser arm in parsers/iterm2.zig emitting Command.iterm2_report_cell_size (void)
  • Stream OSC dispatch emits .size_report with the new style
  • sendSizeReport (termio) and reportSize (libghostty-vt embedders) both pick up the new variant through their existing switches

Result: libghostty-vt embedders that implement effects.size get the ReportCellSize response without any C-side or apprt-side work.

Parser permissiveness

  • ReportCellSize -> emit query
  • ReportCellSize= -> emit query (defensive, matches FileEnd= precedent)
  • ReportCellSize=non-empty -> reject (would collide with the response shape)

Tests

  • 4 parser tests: bare key, lowercase, = empty value accepted, =non-empty rejected
  • 1 encoder test plus the existing exhaustive max-values test extended to cover the new variant
  • Full suite green on Windows (1984 tests) and macOS

Test plan

  • zig build test passes on Windows
  • zig build test passes on macOS (via SSH bundle)
  • Interactive probe with imgcat once we have a Wintty.exe build

deblasis added 2 commits May 19, 2026 07:43
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").
@deblasis deblasis marked this pull request as ready for review May 19, 2026 06:47
@deblasis deblasis merged commit 6ee92f7 into windows May 19, 2026
98 checks passed
@deblasis deblasis deleted the kitten-into-wintty/iterm2-report-cell-size branch May 19, 2026 06:47
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.
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