Skip to content

terminal: add ScreenFormatter.pin_offsets#12882

Closed
jparise wants to merge 1 commit into
ghostty-org:mainfrom
jparise:formatter-pin-offsets
Closed

terminal: add ScreenFormatter.pin_offsets#12882
jparise wants to merge 1 commit into
ghostty-org:mainfrom
jparise:formatter-pin-offsets

Conversation

@jparise

@jparise jparise commented May 31, 2026

Copy link
Copy Markdown
Contributor

When you want to know where specific Pins land in formatter output but don't need the full per-byte Pin array, pin_offsets is a lighter alternative to pin_map. The caller supplies a list of Pins to watch and the formatter fills in the byte offset where each one first appears in the emitted output.

Internally, PageListFormatter scans the per-chunk Coordinate scratch buffer it already builds for pin_map consumers, so PageFormatter itself is unchanged. pin_map and pin_offsets can be set independently or together; when neither is set, no scratch buffer is allocated.

A future caller that needs only a handful of positions can avoid the cumulative pin_map allocation. For a 10MB scrollback that's ~160MB of transient Pin storage traded for ~360KB of per-chunk scratch.

When you want to know where specific Pins land in formatter output but
don't need the full per-byte Pin array, pin_offsets is a lighter
alternative to pin_map. The caller supplies a list of Pins to watch and
the formatter fills in the byte offset where each one first appears in
the emitted output.

Internally, PageListFormatter scans the per-chunk Coordinate scratch
buffer it already builds for pin_map consumers, so PageFormatter itself
is unchanged. pin_map and pin_offsets can be set independently or
together; when neither is set, no scratch buffer is allocated.

A future caller that needs only a handful of positions can avoid the
cumulative pin_map allocation. For a 10MB scrollback that's ~160MB of
transient Pin storage traded for ~360KB of per-chunk scratch.
@jparise jparise requested a review from a team as a code owner May 31, 2026 20:57
@ghostty-bot ghostty-bot Bot added the vt Control sequence related label May 31, 2026
// track Pins directly. When the caller has asked for a pin_map
// or pin_offsets we feed PageFormatter a per-byte Coordinate
// scratch buffer and convert to Pins at the chunk boundary.
const PointMap = struct {

@jparise jparise May 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an opportunity to hoist up this type and share it between PageListFormatter and PageFormatter:

point_map: ?struct {
alloc: Allocator,
map: *std.ArrayList(Coordinate),
},

... but that will trigger a bunch of test code updates too, and I didn't want to make this initial PR too noisy.

If the pin_offsets idea looks good, I can add another commit here that shares the type, or we can look at it in a separate change.

@jparise

jparise commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

The initial motivation for this capability is a more efficient "slice of the entire screen that's currently visible" search for #12881.

@jparise jparise added this to the 1.4.0 milestone May 31, 2026
@jparise

jparise commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

This isn't quite the right shape for the current version of #12881. I'm going to close this now and will revisit as a future optimization.

@jparise jparise closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vt Control sequence related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant