Repository navigation
refactor(picker): read terminal size once from a canonical reader - #3219
Merged
Merged
Conversation
The picker's startup path read terminal dimensions from two sources: the layout sizing used terminal_size::terminal_size() (stdout-first, (80,24) fallback), while skim_list_width used display::terminal_width() (stderr-first, COLUMNS fallback). On a terminal where stdout and stderr point to different places, the preview sizing and the list-column width could observe different widths. Add terminal_dimensions() -> Option<(usize, Option<usize>)> as the canonical reader (stderr, then stdout, then COLUMNS); terminal_width() becomes its width projection, so all its existing callers are unaffected. The height is Option because COLUMNS has no height counterpart. The picker now reads it once and derives both the layout and skim_list_width from that single snapshot. skim_list_width is byte-identical (same chain, same usize::MAX fallback). The only behavior change is the layout honoring the stderr/COLUMNS width when stdout isn't a TTY (redirected stdout, or the headless dry-run/bench paths), which is exactly the divergence being closed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Jun 25, 2026
The canonical-reader switch left two picker fallback arms unexercised by the dry-run suite, because the test harness always sets COLUMNS=150 (a width is always detected, and 150 always selects the Right layout): the `None => (80, 24)` full fallback and the `PreviewLayout::Down` list-width arm. Add two focused dry-run tests — one with COLUMNS removed (no width at all → default dimensions) and one with a narrow COLUMNS (→ Down layout). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Reconciles the canonical terminal-reader change with #3214 (the picker now lays its table out at full width regardless of preview layout): `skim_list_width` takes the full width from the same `term_dims` snapshot, dropping the obsolete Right/Down split. Also refines the layout fallback: a width-only `COLUMNS` reading (height `None`) now falls back to 80x24 for the layout, exactly as before — the layout trusts `term_dims` only when a real terminal supplied both dimensions, while `skim_list_width` still uses the `COLUMNS` width. This keeps the change a no-op for real terminals and preserves the prior headless behavior, so the two added dry-run tests (which targeted the now-removed COLUMNS-drives-layout arms) are dropped — existing PTY and dry-run tests cover both layout arms. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Jun 25, 2026
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.
PR #3210 collapsed the picker's repeated
terminal_size()reads into one, but left the startup path reading dimensions from two different sources: the layout sizing usedterminal_size::terminal_size()(stdout-first,(80, 24)fallback) whileskim_list_widthuseddisplay::terminal_width()(stderr-first,COLUMNSfallback). On a terminal where stdout and stderr point to different places, the preview sizing and the list-column width could observe different widths.This adds
terminal_dimensions() -> Option<(usize, Option<usize>)>instyling/mod.rsas the single canonical reader, with the existing probe chain: stderr, then stdout, thenCOLUMNS.terminal_width()becomes its width projection (terminal_dimensions().map(|(w, _)| w)), so its external contract and all six other callers are untouched. The height isOptionbecauseCOLUMNSsupplies a width with no height counterpart.The picker reads the canonical source once as
term_dimsand derives both the layout andskim_list_widthfrom that one snapshot.The height carries the "real terminal detected" signal
The layout needs both width and height, so it trusts the snapshot only when a real terminal supplied both —
Some((w, Some(h))). A width-onlyCOLUMNSreading (Some((w, None))), or no reading at all, falls back to80x24for the layout, exactly as the old stdout-only read did.skim_list_widthneeds only a width, so it still uses theCOLUMNSwidth via the same snapshot. This resolves theCOLUMNS/height asymmetry cleanly: the same read serves both callers, theOption<height>is load-bearing, and the prior fallback behavior is preserved.Behavior
For a real terminal — the picker requires a TTY, so the normal case — both the layout and
skim_list_widthsee the detected dimensions, so the change is a no-op.terminal_width()is byte-identical for every input, leaving its callers (progress,help,styling::format,commands::mod,list::layout,list::collect) unaffected. The one observable change is the rare split where stdout is not a TTY but stderr is: the layout now tracks the real terminal via the stderr probe (matchingskim_list_widthand what skim renders on) instead of falling back to80x24.list::progressive_tablekeeps its own stdout-only height probe:wt listrenders to stdout, so it must detect a real stdout TTY rather than a stderr/COLUMNSfallback; folding it into the stderr-first reader would change its behavior, so it stays separate.This branch also merges
main, reconciling with #3214 (the picker now lays its table out at full width regardless of preview layout):skim_list_widthtakes the full width from the sameterm_dimssnapshot, dropping the obsolete Right/Down split.Both layout arms and the width derivation are covered by the existing PTY picker tests (real terminal) and dry-run tests (
COLUMNS-only fallback); two unit tests lock theterminal_width↔terminal_dimensionsdelegation. The full local gate is green apart fromtest_switch_picker_alt_l_does_not_hscroll, a picker PTY snapshot that is environment-sensitive on macOS (it fails the same way onmainlocally) and passes on CI — the change is output-neutral for it.