refactor: lift the session out of the web module, and draw a frame in one write - #13
Merged
Merged
Conversation
`io::stdout()` is line buffered and a Ratatui frame carries no newlines, so a frame left this process in whatever pieces the buffer happened to cut it into. On Windows each piece is a separate console write for the host to re-parse — the expensive path, and the one where a frame can be torn across writes. A `BufWriter` sized for a full-screen redraw with per-cell styling turns that into one write per `flush`, which Ratatui already performs exactly once per `draw`. The terminal type is named `TuiTerminal` and built by `open_terminal`, so the three screens that draw share one definition rather than spelling the backend out apiece.
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.
Structural cleanup with no intended change in behaviour, plus one
performance fix that fell out of it.
Net effect across the range: 297 files, +7346 / -8111.
The session is its own thing now
src/web/viewer/had grown to hold state that has nothing to do withserving HTTP — the repository catalog, the preference store, the
size-ownership rules, config reload. A browser tab and an attached TUI
are both clients of that state, so it moved out from under the web
module and into
src/session/:web/viewer/catalog/→session/catalog/web/viewer/prefs/→session/prefs/web/viewer/session.rs→session/operations.rsweb/viewer/{reload,size_owner,runtime}→session/…src/cli.rssplit along its subcommands (cli/{attach,daemon,init,stop}.rs),and the PTY and git-tree test files split by what they cover
(
pty_tests/{identity,lifecycle,relaunch}.rs,git/tree/tests/{listing,path_security,search}.rs) rather than sitting inone file each.
The viewer's App component stopped being the whole app
viewer-ui/src/pages/App.tsxlost 265 lines to hooks that own one concernapiece —
useRepoWorkspacefor the repository/tab state, andterminalSocketMessages.tsfor the socket protocol thatuseTerminalSockethad inlined. Same protocol, decoded in one place instead of inside the
component that consumes it.
Comments
The first commit removes roughly a thousand lines of comment that restated
the line below them. What is left is the reasoning that is not recoverable
from the code — which is the standard the rest of the tree already holds.
One behaviour change:
perf(tui)io::stdout()is line buffered and a Ratatui frame carries no newlines, soa frame left the process in whatever pieces the buffer happened to cut it
into. On Windows each piece is a separate console write for the host to
re-parse — the expensive path, and the one where a frame can tear across
writes. A
BufWritersized for a full-screen redraw with per-cell stylingmakes it one write per
flush, which Ratatui already performs exactly onceper
draw.Verification
All four gates pass locally on Windows (
build,test,clippy -D warnings,fmt --check); CI runs them on macOS, Linux, and Windows.