Repository navigation
fix: force Down layout in narrow terminals for readable branch names - #1564
Conversation
When the terminal is narrower than 80 columns, the Right (side-by-side) preview layout gives the list panel too few columns for branch names to be readable. This adds a minimum width check to auto_detect() so narrow terminals (e.g. phones) always use Down layout regardless of aspect ratio. Closes #1563 Co-authored-by: Claude <[email protected]>
|
do we have enough space for two panes? can you show some examples of what this would look like at various sizes? possibly we default down to a single pane? |
|
Good question. Here's what each layout gives the list and preview panels at various widths (assuming 24 rows, 90% height = ~21 usable rows, 5 worktrees):
Before this PR, 60×24 and 40×24 would get Right layout (30/20 col list — unreadable branch names). Down layout is better than Right here, but you raise a fair point — at 60 or 40 cols, the preview is still competing for vertical space and the preview content ( Defaulting to no preview below some width threshold (maybe 60 cols?) would keep things clean on very narrow terminals. The user could still toggle preview on if they want. Want me to add a hidden-preview mode for narrow terminals? |
|
@armstrjare WDYT? should we go to a single pane on a sufficiently small screen? @worktrunk-bot are there any other ideas for how to organize this? what do other tools do? I worry we're going to end up with a patchwork of if/then/else for deciding what to show... |
|
Good concern about the patchwork. Here's what I've seen in other tools and a suggestion: What other tools do:
The zellij/k9s pattern is the cleanest fit here: a single decision function that maps dimensions → layout tier, with fewer tiers being better. Concrete proposal — three tiers, one function: enum PreviewLayout {
Right, // ≥100 cols + landscape: side-by-side
Down, // ≥60 cols or portrait: preview below
Hidden, // <60 cols: list only, alt-p to toggle preview on
}That's still one The threshold numbers (100/60) are bikesheddable, but the shape of the logic stays simple either way. Want me to go this direction? |
|
@max-sixty Sounds good, I think on small screens the less displayed the better. One alternative to your implementation for simplicity you could just consider small terminals an edge case and for those small screens to display an entirely different ultra basic TUI with just a list selector with branch name. Or an option to toggle a —minimal vs —detailed with default accordingly @worktrunk-bot I think at the moment if a branch/worktree name is longer than the number of columns it just doesn’t show? If so, is it possible to trim the worktree names when they are too long? Better to see something rather than nothing at all. |
|
Good news on the trimming question — long branch names are already truncated with The real issue this PR fixes is the layout choice — before, a 60-column terminal would pick Right (side-by-side) layout, giving the branch list only ~30 columns. With this fix it picks Down layout, giving the list the full 60 columns. That plus the existing truncation means you always see something useful. Re: the broader direction — @max-sixty's question about the three-tier approach (Right → Down → Hidden) and whether to add a Hidden mode for very narrow terminals is the next step. That keeps it to one clean |
|
@worktrunk-bot Another thought - at the moment if the terminal changes dimensions while the TUI is displayed, it doesn’t appear to update its correctly (unless this is a Mosh specific issue that I’m experiencing?) Is this accurate? This prevents changing from portrait to landscape to see the side by side properly. |
@worktrunk-bot |
|
That's accurate — the layout is determined once at startup and doesn't update on resize. The underlying skim library (via skim-tuikit) does handle SIGWINCH to redraw the UI chrome, so the list itself will reflow on resize. But worktrunk's layout tier and preview dimensions stay fixed — so if you rotate a phone from portrait to landscape mid-session, you'd stay in Down layout with preview content sized for the original dimensions. This isn't Mosh-specific — it would happen in any terminal. Mosh may make it more noticeable since it buffers resize events differently than a direct SSH connection. Making layout reactive to resize would require listening for dimension changes and regenerating previews on the fly, which is a larger change than what this PR tackles. Could be worth a follow-up issue if it's causing friction in practice. |
|
Good catch — what's happening here is worse than truncation to 1 character. The branch column is being dropped entirely. The column allocator in This PR helps because it forces Down layout on narrow terminals, giving the list the full terminal width — making it much more likely that branch names fit. But the deeper issue is that the branch column should degrade gracefully (truncate with On the resize question from your other comment — correct, layout is computed once at startup and doesn't adapt to terminal resize mid-session. |
|
to confirm, is the issue above re 1-column wide names only relevant on resizings? @worktrunk-bot can you explain how we get that? in another PR, can you generate the view of the picker at a range of sizes (no resizing after start) with snapshots; no code changes? |
|
On the 1-char names question: No, it's not only relevant on resizing — it can happen at a fresh startup too. The root cause is In the picker with Right layout, the list gets This PR helps because Down layout gives the list the full 60 cols. But the deeper issue is that the allocator should let Branch shrink to a minimum width rather than requiring its full ideal width — worth a separate fix. On the snapshot PR: Will do — I'll create a separate PR with |
…l sizes Adds snapshot tests showing `wt list` output at 30–120 columns to visualize which columns appear and how branch names render at each width. Includes picker-equivalent widths (terminal_width/2) to show what `wt switch` in Right layout would display. Context: #1564 Co-Authored-By: Claude Opus 4.6 <[email protected]>
let's make a new PR which adjust this so that branch gets priority; doesn't get collapsed to zero. think of a way of doing this that maintains as much simplicity and generality as possible in our algorithm that decides width |
|
Created #1626 for this. The approach: add a
|
) ## Summary - Add `shrinkable` flag to `ColumnSpec` — shrinkable columns degrade gracefully to whatever width fits (down to header width) instead of being dropped entirely when their ideal width doesn't fit - Mark `Branch` as the only shrinkable column, so branch names are always visible even on narrow terminals or in the picker's side-by-side layout - The mechanism is general (any column could opt in) but only Branch needs it — keeping the change minimal **Before:** On a 60-column terminal with Right layout (30 cols for list), if the longest branch name exceeded ~26 chars, the Branch column was dropped entirely — showing Status/HEAD± columns instead, which is what @armstrjare's screenshot in #1564 showed. **After:** Branch shrinks to fit the available space, truncated with `…` by the existing `truncate_visible()` renderer. Branch names are always visible. ## Test plan - [x] New unit test `test_try_allocate_with_min_width` — verifies ideal→min fallback behavior - [x] New unit test `test_branch_column_never_dropped` — verifies Branch is present at 30 cols with a long branch name - [x] All 467 unit tests pass - [x] Pre-existing integration test failures confirmed on `main` (not introduced by this PR) Spun off from discussion in #1564 (comment by @max-sixty). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>

Problem
On narrow terminals (e.g. phones),
wt switchuses a side-by-side (Right) layout that splits the terminal 50/50 between list and preview. When the terminal is only 60 columns wide, the list gets 30 columns — too narrow for branch names to be readable, making it impossible to identify worktrees.The
PreviewLayout::auto_detect()function only considered aspect ratio, not absolute width. A 60×24 terminal has a landscape aspect ratio ((60/24) * 0.5 = 1.25), so it selected Right layout despite being too narrow.Solution
Added a minimum column width check (
MIN_COLS_FOR_RIGHT_LAYOUT = 80) toauto_detect(). Terminals narrower than 80 columns now always use Down layout (preview below list), giving the branch list the full terminal width.Also extracted
for_dimensions(cols, rows)fromauto_detect()for direct unit testing of the layout decision logic.Testing
pre-commit run --all-filespasses (excluding lychee which isn't installed)Closes #1563 — automated triage