Repository navigation
Description
Problem
Body variants are currently named after the renderer that consumes them (`Bignum`, `Sparkline`, `LineChart`, `BarChart`, `Gauge`), which collapses the 1:N relationship between data shape and renderer implementation.
A clock widget outputs a short string. "Show it as a big tui-big-text clock" is one choice, but "show it in figlet ASCII art" or "animate it as a flip clock" or "just render it as plain text" are equally valid. The current design can't express any of those — the Body variant picks the renderer.
Proposed model
Three independent axes:
- Fetcher — produces data of a given shape (clock → short string, github → bars, disk → ratio, …).
- Shape — data-shape naming, not render naming: `String / Lines / NumberSeries / PointSeries / Bars / Entries / Ratio / Image`.
- Renderer — consumes one or more shapes and draws. Multiple renderers can declare support for the same shape:
- `String` → `simple` / `bignum_tui` (tui-big-text) / `ascii_art` (figlet-rs) / `animated_typewriter`
- `Lines` → `simple` / `boxed` / `marquee`
- `Ratio` → `gauge_bar` (ratatui::Gauge) / `gauge_donut` (custom)
- `NumberSeries` → `sparkline` / `chart_ascii`
- `PointSeries` → `chart_line` (ratatui::Chart) / `chart_ascii_line`
Config selects the renderer by name; the renderer's options are its own type.
```toml
render = "simple" # short form, default options
render = { type = "bignum_tui", pixel_size = "quadrant" } # full form, renderer-specific params
```
Renderer ≈ ratatui widget
Each renderer is essentially a ratatui-widget factory. Built-in renderers construct `Paragraph` / `Gauge` / `Chart` / `Sparkline` / ratatui widgets (or composites), plus optionally widgets from other crates (`tui-big-text`, `figlet-rs`, future custom widgets).
ratatui's `Widget` trait takes `self` by value, which doesn't match how we need to pass per-call options / frame references. Our `Renderer` trait will be a thin adapter:
```rust
pub trait Renderer: Send + Sync {
fn name(&self) -> &str;
fn accepts(&self) -> &[Shape];
fn render(&self, frame: &mut Frame, area: Rect, body: &Body, opts: &RenderOptions);
}
```
Each impl builds and calls `frame.render_widget(...)`.
Compatibility + fallback
- Fetcher's shape vs config's renderer.accepts: match → render. Mismatch → render "renderer X cannot display shape Y" placeholder + log. Never panic.
- No renderer configured → pick a default for the shape (`String` → `simple`, `Ratio` → `gauge_bar`, etc.)
Scope of the initial PR
- Shape enum — rename `Body` variants to data-shape names (`Bignum` → `String`, `Sparkline` → `NumberSeries`, `LineChart` → `PointSeries`, `BarChart` → `Bars`, `Gauge` → `Ratio`, `Text` → `Lines`, `List` → `Entries`, `Image` stays). Update serde tags and cache schema.
- `Renderer` trait + `Registry` + `RenderOptions` — mirrors the Fetcher registry.
- Port existing 8 renderers — rewrite as `Renderer` impls that construct ratatui widgets. Behavior unchanged; each is named after what it currently does (`bignum_tui`, `sparkline`, `chart_line`, …).
- Config parsing — `RenderSpec` as `#[serde(untagged)]` that accepts either a bare string or a tagged table with renderer-specific options.
- Dispatch in runtime — resolve renderer from config, compat-check vs fetcher shape, render or placeholder.
- `WidgetConfig.render` stops being dead — runtime actually consults it.
Out of scope (future PRs):
- New alt renderers (`ascii_art`, `animated_typewriter`, `gauge_donut`, `chart_ascii`) — land one-by-one after the registry exists.
- Plugin-contributed renderers — core: Plugin protocol (subprocess-based I/O spec) #5 plugin work.
- Theming / color — feat: Theme / color scheme system #17.
Depends on
- none (pure refactor)
Blocks
- Every future renderer PR (ASCII art / animated / custom charts) — shouldn't land until the registry exists, otherwise they'd need re-plumbing after.
Activity
Merge pull request #34 from unhappychoice/refactor/32-renderer-registry