Skip to content

core: renderer registry + data-shape / renderer decoupling (3-axis) #32

Closed

Description

@unhappychoice

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

  1. 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.
  2. `Renderer` trait + `Registry` + `RenderOptions` — mirrors the Fetcher registry.
  3. 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`, …).
  4. Config parsing — `RenderSpec` as `#[serde(untagged)]` that accepts either a bare string or a tagged table with renderer-specific options.
  5. Dispatch in runtime — resolve renderer from config, compat-check vs fetcher shape, render or placeholder.
  6. `WidgetConfig.render` stops being dead — runtime actually consults it.

Out of scope (future PRs):

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

  1. added
    core
    on Apr 21, 2026
  2. added a commit that references this issue on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions