O3: positron-ratatui — terminal Renderer + Host loop (outlier A)#7
Merged
Conversation
O3 of the define-once roadmap: the first real stateful `Renderer` + `Host`
event loop, validating positron's contract against a genuinely different
`type Output` than counter-cli's `String` — real terminal *cells* (any
ratatui `Widget`), drawn into a ratatui `Buffer`.
Three single-purpose pieces:
- `render_to_buffer` — project a `ViewState` through a `Renderer` into a
headless `Buffer`; the primitive both loops and every test build on.
- `TerminalHost` — the `Host` impl: state-down via `on_state`, event-up via
a boxed key map. Owns no terminal I/O, so the state/event contract is
unit-testable without a TTY.
- `drive` (headless, generic over `Backend` → `TestBackend` in tests) +
`run_crossterm` (thin live-TTY wrapper). Both share one dispatch `step`
and one `redraw`, so the state-down/event-up decision lives in one place.
The `examples/counter_tui.rs` demo renders the *same* `Counter` `ViewState`
the tests render headlessly — nothing about the view changes between a
`TestBackend` assertion and a real terminal ("define once, project many").
ratatui 0.29 pinned in workspace deps; consumers use `ratatui::crossterm`
(its re-export) so there's no separate-crossterm version-skew risk.
Docs: ARCHITECTURE.md + README mark O1–O3 landed, O4 (positron-wgpu,
outlier B) next.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…nly gating Two review nits from PR #7, both fail-loud correctness: - run_crossterm restored the terminal with `?`, so a restore failure would mask the loop's root-cause error. Now `result.and(restore)` surfaces the loop error first; a restore error only wins when the loop succeeded. Fail loud and NAME the cause. - The live-loop Press/quit/resize gating was untested and the doc overclaimed it as exercised by `drive`. Extracted the pure decision into `classify(event, quit_on) -> LoopAction` so it is unit-tested headlessly (Press dispatches, Release is ignored, quit leaves, resize redraws, non-key ignored). Only the blocking `event::read` I/O is now genuinely TTY-bound; the doc says exactly that. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
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.
O3 — the first real stateful
Renderer+Hostevent loopValidates positron's contract against a genuinely different
type Outputthancounter-cli'sString: real terminal cells (any ratatuiWidget), drawn into a ratatuiBuffer. This is outlier A in the outlier-validation discipline — the wgpu GPU renderer (O4) is outlier B.What's here (
positron-ratatui, three single-purpose pieces)render_to_buffer— project aViewStatethrough aRendererinto a headlessBuffer. The primitive both loops and every test build on.TerminalHost— theHostimpl: state-down viaon_state, event-up via a boxed key map. Owns no terminal I/O, so the state/event contract is unit-testable without a TTY (render_currentrenders straight into aBuffer).drive(headless, generic overBackend→TestBackendin tests) +run_crossterm(thin live-TTY wrapper). Both share one dispatchstepand oneredraw— the state-down/event-up decision lives in exactly one place.Define once, project many
examples/counter_tui.rsrenders the sameCounterViewStatethe tests render headlessly — nothing about the view changes between aTestBackendassertion and a real terminal.Tests (one mod, each with
// what this catches:)RendererwhoseOutputis real cells (not aString) projects into aBufferat the expected position — the whole reason this is outlier ATerminalHosthonors state-down (store + render) and event-up (key→command; unmapped→None)driveruns the full state-down/event-up cycle headlessly viaTestBackendNotes
0.29pinned in workspace deps; consumers useratatui::crossterm(its re-export) → no separate-crossterm version-skew.ARCHITECTURE.md+READMEmark O1–O3 landed, O4 (positron-wgpu, outlier B) next.Validated:
cargo fmt --checkclean,cargo clippy --all-targets -- -D warningsclean,cargo test -p positron-ratatui= 3 passed, example builds.🤖 Generated with Claude Code