fix: force Down layout in narrow terminals for readable branch names#1564
fix: force Down layout in narrow terminals for readable branch names#1564worktrunk-bot wants to merge 1 commit intomainfrom
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 <noreply@anthropic.com>
|
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. |

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