tui-theme-builder

Crates.iotui-theme-builder
lib.rstui-theme-builder
version0.2.2
created_at2025-02-08 12:36:36.836802+00
updated_at2026-01-17 19:46:33.005305+00
descriptionTheme deserializer for Ratatui
homepage
repositoryhttps://github.com/preiter93/tui-theme-builder
max_upload_size
id1548014
size57,652
Philipp Reiter (preiter93)

documentation

README

tui-theme-builder

Crates.io Badge Deps.rs Badge

A theme builder macro for ratatui apps.

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

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

#[derive(ThemeBuilder)]
#[builder(context=Config)]
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,

    /// Annotate border types with 'value=field' to reference a context field,
    /// or use a variant name directly, e.g. 'plain', 'rounded', 'thick', etc.
    /// Note: If accessed with 'value=field' the 'field' must start with a
    /// capital letter.
    #[border_type(value = border_type)]
    pub border: BorderType,
}

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

fn main() {
    let config = Config::default();
    let theme = Theme::build(&config);
}

Apps using tui-theme-builder

Commit count: 25

cargo fmt