1 unstable release

new 0.1.0 Feb 8, 2025

#996 in Parser implementations

MIT license

16KB

tui-theme-builder

Deps.rs Badge

A theme builder macro for ratatui apps.

use ratatui::style::{Color, Style};
use serde::Deserialize;
use tui_theme_builder::ThemeBuilder;

#[derive(Debug, Deserialize)]
pub struct Colors {
    pub orange: Color,
    pub purple: Color,
}

#[derive(ThemeBuilder)]
#[builder(context=Colors)]
pub struct Theme {
    /// Annotate styles with 'fg=color', 'bg=color' or add modifiers,
    /// e.g. 'bold' or 'underlined'.
    #[style(fg=orange, bg=purple, bold, underlined)]
    pub base: Style,
}

impl Default for Colors {
    fn default() -> Self {
        let s = r##"
        "orange" = "#ffb86c"
        "purple" = "#bd93f9"
        "##;
        toml::from_str(s).unwrap()
    }
}

fn main() {
    let colors = Colors::default();
    let theme = Theme::build(&colors);
}

Apps using tui-theme-builder

Dependencies

~7–16MB
~220K SLoC