Skip to main content

ishou_render/
tui.rs

1//! TUI renderer — emits Rust code binding ishou colors to ratatui /
2//! crossterm `Color::Rgb`. Designed to be pasted into a TUI app's `theme.rs`
3//! or written to a file and included via `include!`.
4
5use ishou_tokens::TokenSet;
6
7pub fn render(t: &TokenSet) -> String {
8    let mut out = String::from(
9        "// ishou — pleme-io TUI color bindings (generated)\n\
10         // Compatible with ratatui::style::Color and crossterm::style::Color.\n\n\
11         pub mod ishou_tui {\n",
12    );
13    for (k, v) in t.color.entries() {
14        out.push_str(&format!(
15            "    /// {name}\n    pub const {ident}: (u8, u8, u8) = ({}, {}, {});\n",
16            v.r,
17            v.g,
18            v.b,
19            name = k.replace('_', "-"),
20            ident = k.to_uppercase(),
21        ));
22    }
23    out.push_str("\n    /// ratatui integration: `ratatui::style::Color::Rgb(r, g, b)` from a tuple.\n");
24    out.push_str(
25        "    #[cfg(feature = \"ratatui\")]\n    \
26         pub fn r(rgb: (u8, u8, u8)) -> ratatui::style::Color {\n        \
27         ratatui::style::Color::Rgb(rgb.0, rgb.1, rgb.2)\n    }\n",
28    );
29    out.push_str("\n    /// crossterm integration.\n");
30    out.push_str(
31        "    #[cfg(feature = \"crossterm\")]\n    \
32         pub fn c(rgb: (u8, u8, u8)) -> crossterm::style::Color {\n        \
33         crossterm::style::Color::Rgb { r: rgb.0, g: rgb.1, b: rgb.2 }\n    }\n",
34    );
35    out.push_str("}\n");
36    out
37}