Skip to content

fix(tui): auto-collapse the sidebar on small screens - #479

Merged
dimetron merged 2 commits into
mainfrom
fix/sidebar-portrait
Nov 17, 2026
Merged

dimetron merged 2 commits into
mainfrom
fix/sidebar-portrait

Conversation

@dimetron

@dimetron dimetron commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

What

Rebased onto merged main and reworked: the sidebar auto-collapses on small
screens instead of disappearing.
Resolves the conflict with #481, which added
the collapse toggle after this branch had already landed its own hide rule.

Why the rework

After #479 and #481 both landed, the sidebar had three ways to vanish:

Trigger Result
frame ≤ 80 columns (#479) sidebar dropped, no restore control
portrait frame (#479) sidebar dropped, no restore control
version-row toggle (#481) one-column strip with ‹

Two of those were a one-way trip: on exactly the frames that needed the columns
back, the panel left nothing to click. If you narrowed your window, the sidebar
was gone and no glyph could bring it back.

Now there is one rule with one output. sidebarFits() answers whether this frame
can afford SidebarWidth columns — too narrow for a readable chat beside it, or
portrait, and it cannot. sidebarWidth() turns that plus the user's toggle into
a width: SidebarWidth or the one-column strip, never 0. The strip is one
column, which every frame that can draw a chat can seat, so the sidebar is never
absent, only wide or narrow.

The rule fires on resize, and is a pure function of the frame

sidebarCollapsed (the user's toggle) and sidebarFits() (the frame) are read
on every render; nothing caches "the rule already ran". A stored flag would be
one edit away from going stale, and a stale one shows the expanded panel on a
phone.

sidebarExpanded carries the one thing a render cannot re-derive: the user
clicking the strip on a small frame to override the rule for that frame.
Without it the rule would re-collapse on the very next frame and the click would
appear dead. A resize clears it — the moment the user asks for the layout to be
decided again.

Behaviour

Frame Sidebar
40×24 … 99×N strip (1 col)
100×30, 120×40, 200×60 expanded (28 cols)
100×120 (portrait) strip
160×160 (square) expanded — a square is not portrait
unsized (h=0) expanded — unknown is not small

Clicking the strip on a small frame expands it for that frame; a resize applies
the rule again.

A bug caught while wiring it up

The toggle flipped the preference flag rather than the visible state. On a small
frame the strip is up because the rule collapsed it, with the flag still
false — so the click left the strip up and the control looked dead. It now flips
the visible state. TestClickingTheStripOnASmallFrameExpandsIt fails if it goes
back to reading the flag.

Verification

Check Result
go build ./... ✅
go test ./internal/tui ./internal/extension ✅
make lint ✅ 0 issues
make vet ✅ clean

Guards seen red before green:

  • rule disabled in sidebarWidth → the four small-screen tests fail
  • toggle reads the flag instead of the visible state → both toggle tests fail
  • frame matrix printed and checked by hand at ten sizes (40×24 … 200×60)

Five pre-existing tests encoded the old hide-it contract (mainWidth at 60
columns, the symmetric-gap row helper, the absent-strip case, the width floor)
and were updated to the new one.

Not verified visually in a real terminal: the strip was confirmed through
View() render assertions at 90 and 160 columns, not a live session.

@dimetron
dimetron force-pushed the fix/sidebar-portrait branch from 485fa58 to 808b516 Compare November 17, 2026 07:55
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.51%. Comparing base (ede50f7) to head (784bf5e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #479      +/-   ##
==========================================
- Coverage   91.51%   91.51%   -0.01%     
==========================================
  Files         395      395              
  Lines       50732    50736       +4     
==========================================
+ Hits        46427    46429       +2     
- Misses       4299     4301       +2     
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

dimetron and others added 2 commits November 17, 2026 14:00
The sidebar is 23 fixed columns, which is a good trade on a landscape
terminal and a bad one on a portrait window — the mobile case, where
`pi serve` is opened from a phone browser. There a tall, narrow frame
spent a quarter of its width on a column of short labels while the chat,
the only thing being read, was squeezed into what was left. The columns
were returned to the chat by `mainWidth`, but `sidebarVisible` is the
rule, so `View` and the width math cannot disagree.

The threshold stays the existing one (`width > 80`), since below that the
panel would be 57 columns: portrait orientation does not make a narrow
sidebar affordable, it removes the reason to try. A height of zero is an
unsized frame rather than a portrait one, so a model built before the
first `WindowSizeMsg` keeps its sidebar and renders the same geometry it
will after one.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: pi <dimetron@me.com>
The sidebar had three ways to disappear after #479 and #481 merged: a frame
at or below 80 columns dropped it outright, a portrait frame dropped it
outright, and the version-row toggle collapsed it to a strip. Two of those
left no control behind, so on exactly the frames that needed the columns
back the sidebar became a one-way trip — no strip, no glyph, nothing to
click.

They are now one rule with one output. sidebarFits answers whether this
frame can afford SidebarWidth columns: too narrow for the chat beside it,
or portrait, and it cannot. sidebarWidth turns that plus the user's toggle
into a width — SidebarWidth or the one-column strip — and never returns 0.
The strip is one column, which every frame that can draw a chat can seat,
so the sidebar is never absent, only wide or narrow, and the control that
undoes a collapse is always on screen.

The rule fires on resize and is a pure function of the frame, not a stored
"already applied" flag. A cached flag would be one edit away from going
stale, and a stale one shows the expanded panel on a phone. sidebarExpanded
carries the one piece of state a render cannot re-derive: the user clicking
the strip on a small frame to expand it, which the rule would otherwise
undo on the very next frame. A resize clears it, which is the moment the
user is asking for the layout to be decided again.

The toggle now flips the visible state rather than the preference flag. On
a small frame the strip is up because the rule collapsed it, with the flag
still false — flipping only the flag there left the strip up and the
control apparently dead.

Five tests encoded the old hide-it contract (mainWidth at 60 columns, the
symmetric-gap row helper, the absent-strip case, and the width floor) and
were updated to the new one.

Signed-off-by: pi <dimetron@me.com>
@dimetron
dimetron force-pushed the fix/sidebar-portrait branch from 808b516 to 784bf5e Compare November 17, 2026 13:10
@dimetron dimetron changed the title fix(tui): hide the right sidebar in a portrait frame fix(tui): auto-collapse the sidebar on small screens Nov 17, 2026
@dimetron

Copy link
Copy Markdown
Owner Author

govulncheck

Gate passes. 9 findings, all in github.com/ollama/ollama, none with a released fix — reported rather than failing, because there is nothing to upgrade to.

This PR adds no dependencies and touches only internal/tui, so none originate here.

No findings with an available fix (9 reported in total).

@dimetron
dimetron merged commit 20f9349 into main Nov 17, 2026
15 checks passed
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