Skip to main content

Crate tca_ratatui

Crate tca_ratatui 

Source
Expand description

Terminal Colors Architecture (TCA) theme support for ratatui.

This crate provides utilities for loading and using TCA themes in ratatui applications. Themes are base24 YAML files.

§Quick Start - StyleSet

The easiest way to theme a ratatui app is with StyleSet. It pre-builds all the common ratatui::style::Styles you need from the user’s configured theme.

use tca_ratatui::StyleSet;
use ratatui::widgets::{Block, Borders, Paragraph};

fn render(frame: &mut ratatui::Frame) {
    let styles = StyleSet::default(); // user's configured theme, or built-in fallback

    let block = Block::default()
        .borders(Borders::ALL)
        .style(styles.border);

    let text = Paragraph::new("Hello, world!")
        .block(block)
        .style(styles.primary);

    frame.render_widget(text, frame.area());
}

Load by name, or cycle through available themes with StyleSetCursor:

use tca_ratatui::{StyleSet, StyleSetCursor};

// Load a specific theme by name (any case format works)
let styles = StyleSet::from_name("tokyo-night");
let styles = StyleSet::from_name("Tokyo Night");

// Cycle through all installed + built-in themes
let mut cursor = StyleSetCursor::with_all_themes();
cursor.next();
cursor.prev();
cursor.set_current("nord-dark");
let styles = cursor.peek().unwrap_or_default();

§Lower-Level Access - TcaTheme

For direct access to typed colors (e.g. for custom ratatui::style::Style composition), use TcaTheme directly:

use tca_ratatui::TcaTheme;
use ratatui::style::Style;

fn example() {
    let theme = TcaTheme::from_name("tokyo-night");
    let theme = TcaTheme::default(); // user's configured default

    // ANSI, semantic, and UI colors are all resolved
    let error_style = Style::default().fg(theme.semantic.error);
    let bg_style = Style::default().bg(theme.ui.bg_primary);
    let red = theme.ansi.red;

    // Raw base24 slots
    let base00 = theme.base24[0]; // darkest background
}

§Parsing from YAML

use tca_ratatui::TcaTheme;

fn example() {
    let yaml = r#"
scheme: "My Theme"
author: "You"
variant: "dark"
base00: "1a1b26"
base01: "16161e"
base02: "2f3549"
base03: "444b6a"
base04: "787c99"
base05: "a9b1d6"
base06: "cbccd1"
base07: "d5d6db"
base08: "f7768e"
base09: "ff9e64"
base0A: "e0af68"
base0B: "9ece6a"
base0C: "7dcfff"
base0D: "7aa2f7"
base0E: "bb9af7"
base0F: "f7768e"
base10: "1a1b26"
base11: "16161e"
base12: "f7768e"
base13: "e0af68"
base14: "9ece6a"
base15: "7dcfff"
base16: "7aa2f7"
base17: "bb9af7"
"#;
    let theme = TcaTheme::try_from(yaml).expect("Couldn't parse YAML");
}

Re-exports§

pub use widgets::ColorPicker;

Modules§

widgets
Terminal Colors Architecture (TCA) widgets for ratatui.

Structs§

Ansi
ANSI 16-color definitions mapped to Ratatui colors.
Meta
Theme metadata.
Semantic
Semantic color roles.
StyleSet
The main StyleSet struct with predefined styles as named fields
StyleSetCursor
A cycling cursor over a collection of StyleSets, backed by a [TcaThemeCursor].
TcaTheme
A fully resolved TCA theme with Ratatui-compatible colors.
TcaThemeBuilder
Builder for constructing a TcaTheme programmatically.
TcaThemeCursor
A cycling cursor over resolved TcaTheme values.
ThemeCursor
A cycling cursor over a list of themes of type T.
Ui
UI element colors for application chrome.