1use 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(
24 "\n /// ratatui integration: `ratatui::style::Color::Rgb(r, g, b)` from a tuple.\n",
25 );
26 out.push_str(
27 " #[cfg(feature = \"ratatui\")]\n \
28 pub fn r(rgb: (u8, u8, u8)) -> ratatui::style::Color {\n \
29 ratatui::style::Color::Rgb(rgb.0, rgb.1, rgb.2)\n }\n",
30 );
31 out.push_str("\n /// crossterm integration.\n");
32 out.push_str(
33 " #[cfg(feature = \"crossterm\")]\n \
34 pub fn c(rgb: (u8, u8, u8)) -> crossterm::style::Color {\n \
35 crossterm::style::Color::Rgb { r: rgb.0, g: rgb.1, b: rgb.2 }\n }\n",
36 );
37 out.push_str("}\n");
38 out
39}