Skip to main content

tca_ratatui/
lib.rs

1//! Terminal Colors Architecture (TCA) theme support for ratatui.
2//!
3//! This crate provides utilities for loading and using TCA themes in ratatui applications.
4//!
5//! ## Quick Start
6//!
7//! ```rust,no_run
8//! use tca_ratatui::TcaTheme;
9//! use ratatui::style::Style;
10//! use std::path::Path;
11//!
12//! fn example() {
13//! // Load a TCA theme from a file or name, with reasonable fallback.
14//! let theme = TcaTheme::new(Some("theme.toml"));
15//! let theme = TcaTheme::new(Some("Tokyo Night"));
16//! let theme = TcaTheme::new(Some("tokyo-night"));
17//! let theme = TcaTheme::new(None);
18//!
19//! // Or from a TOML string.
20//! let toml_str = r###"
21//! [theme]
22//! name = "Tokyo Night"
23//! slug = "tokyo-night"
24//! author = "enkia / TCA Project"
25//! version = "1.0.0"
26//! description = "A clean, dark theme inspired by the city lights of Tokyo at night. Based on Tokyo Night by enkia."
27//! dark = true
28//!
29//! [ansi]
30//! black = "#15161e"
31//! red = "#f7768e"
32//! green = "#9ece6a"
33//! yellow = "#e0af68"
34//! blue = "#7aa2f7"
35//! magenta = "#bb9af7"
36//! cyan = "#7dcfff"
37//! white = "#a9b1d6"
38//! bright_black = "#414868"
39//! bright_red = "#f7768e"
40//! bright_green = "#9ece6a"
41//! bright_yellow = "#e0af68"
42//! bright_blue = "#7aa2f7"
43//! bright_magenta = "#bb9af7"
44//! bright_cyan = "#7dcfff"
45//! bright_white = "#c0caf5"
46//!
47//! # Palette: darkest→lightest
48//! # neutral: bg_dark→fg
49//! # 0=#15161e  1=#1a1b26  2=#24283b  3=#292e42  4=#414868  5=#565f89  6=#a9b1d6  7=#c0caf5
50//! [palette]
51//! neutral = [
52//!   "#15161e",
53//!   "#1a1b26",
54//!   "#24283b",
55//!   "#292e42",
56//!   "#414868",
57//!   "#565f89",
58//!   "#a9b1d6",
59//!   "#c0caf5",
60//! ]
61//! red = ["#6b1a2a", "#db4b4b", "#f7768e"]
62//! green = ["#2d4a1e", "#41a146", "#9ece6a"]
63//! yellow = ["#5c4400", "#c09230", "#e0af68"]
64//! blue = ["#1a2a6b", "#3d59a1", "#7aa2f7"]
65//! purple = ["#3d2370", "#7953c7", "#bb9af7"]
66//! cyan = ["#144a60", "#0db9d7", "#7dcfff"]
67//! orange = ["#5c2e00", "#c47214", "#ff9e64"]
68//! teal = ["#17403d", "#1abc9c", "#73daca"]
69//! magenta = ["#5c1a5c", "#9d4bb6", "#c586c0"]
70//!
71//! [semantic]
72//! error = "palette.red.2"
73//! warning = "palette.orange.2"
74//! info = "palette.cyan.2"
75//! success = "palette.green.2"
76//! highlight = "palette.yellow.2"
77//! link = "palette.blue.2"
78//!
79//! [ui.bg]
80//! primary = "palette.neutral.1"
81//! secondary = "palette.neutral.2"
82//!
83//! [ui.fg]
84//! primary = "palette.neutral.7"
85//! secondary = "palette.neutral.6"
86//! muted = "palette.neutral.5"
87//!
88//! [ui.border]
89//! primary = "palette.blue.1"
90//! muted = "palette.neutral.3"
91//!
92//! [ui.cursor]
93//! primary = "palette.blue.2"
94//! muted = "palette.neutral.5"
95//!
96//! [ui.selection]
97//! bg = "palette.neutral.3"
98//! fg = "palette.neutral.7"
99//! "###;
100//! let theme = TcaTheme::try_from(toml_str).expect("Couldn't parse TOML");
101//!
102//! // Use ANSI colors
103//! let error_style = Style::default().fg(theme.ansi.red);
104//! let success_style = Style::default().fg(theme.ansi.green);
105//!
106//! // Use semantic colors
107//! let error_style = Style::default().fg(theme.semantic.error);
108//! let warning_style = Style::default().fg(theme.semantic.warning);
109//!
110//! // Use UI colors
111//! let bg_style = Style::default().bg(theme.ui.bg_primary);
112//! let fg_style = Style::default().fg(theme.ui.fg_primary);
113//! }
114//! ```
115
116#![warn(missing_docs)]
117
118mod theme;
119
120#[cfg(feature = "widgets")]
121pub mod widgets;
122
123#[cfg(test)]
124mod tests;
125
126pub use theme::{Ansi, Base16, ColorRamp, Meta, Palette, Semantic, TcaTheme, TcaThemeBuilder, Ui};
127
128#[cfg(feature = "fs")]
129pub use tca_types::ThemeCursor;
130
131#[cfg(feature = "fs")]
132pub use theme::TcaThemeCursor;
133
134#[cfg(feature = "widgets")]
135pub use widgets::ColorPicker;