Repository navigation
fix(tui): auto-collapse the sidebar on small screens - #479
Merged
Merged
Conversation
dimetron
force-pushed
the
fix/sidebar-portrait
branch
from
November 17, 2026 07:55
485fa58 to
808b516
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
force-pushed
the
fix/sidebar-portrait
branch
from
November 17, 2026 13:10
808b516 to
784bf5e
Compare
Owner
Author
govulncheckGate passes. 9 findings, all in This PR adds no dependencies and touches only |
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.
What
Rebased onto merged
mainand reworked: the sidebar auto-collapses on smallscreens 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:
‹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 framecan afford
SidebarWidthcolumns — too narrow for a readable chat beside it, orportrait, and it cannot.
sidebarWidth()turns that plus the user's toggle intoa width:
SidebarWidthor the one-column strip, never 0. The strip is onecolumn, 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) andsidebarFits()(the frame) are readon 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.
sidebarExpandedcarries the one thing a render cannot re-derive: the userclicking 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
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.
TestClickingTheStripOnASmallFrameExpandsItfails if it goesback to reading the flag.
Verification
go build ./...go test ./internal/tui ./internal/extensionmake lintmake vetGuards seen red before green:
sidebarWidth→ the four small-screen tests failFive pre-existing tests encoded the old hide-it contract (
mainWidthat 60columns, 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.