ratatui_toolkit/services/theme/mod.rs
1//! Comprehensive theme system for ratatui-toolkit widgets.
2//!
3//! This module provides a complete theming solution for TUI applications,
4//! with support for loading themes from JSON files in the opencode format.
5//!
6//! # Overview
7//!
8//! The theme system consists of:
9//!
10//! - [`AppTheme`] - The main theme struct with all widget colors
11//! - [`ThemeVariant`] - Dark/light mode selection
12//! - [`DiffColors`] - Colors for CodeDiff widget
13//! - [`MarkdownColors`] - Colors for MarkdownWidget
14//! - [`SyntaxColors`] - Colors for syntax highlighting
15//! - [`loader`] - JSON theme file loading utilities
16//!
17//! # Builtin Themes
18//!
19//! The crate includes 33 builtin themes that can be loaded by name:
20//!
21//! ```rust
22//! use ratatui_toolkit::services::theme::{loader, ThemeVariant};
23//!
24//! // Load a builtin theme
25//! let theme = loader::load_builtin_theme("gruvbox", ThemeVariant::Dark)
26//! .expect("Failed to load theme");
27//!
28//! // See all available themes
29//! for name in loader::BUILTIN_THEMES {
30//! println!("{}", name);
31//! }
32//! ```
33//!
34//! # Custom Themes
35//!
36//! You can create custom themes from JSON files or strings:
37//!
38//! ```rust
39//! use ratatui_toolkit::services::theme::{AppTheme, ThemeVariant};
40//!
41//! let json = r#"{
42//! "defs": {
43//! "myPrimary": "#ff6600"
44//! },
45//! "theme": {
46//! "primary": { "dark": "myPrimary", "light": "myPrimary" }
47//! }
48//! }"#;
49//!
50//! let theme = AppTheme::from_json(json, ThemeVariant::Dark)
51//! .expect("Failed to parse theme");
52//! ```
53//!
54//! # JSON Format
55//!
56//! The opencode theme format uses:
57//!
58//! - `defs`: Named color definitions (e.g., `"darkBg0": "#282828"`)
59//! - `theme`: Semantic mappings with variant support
60//!
61//! ```json
62//! {
63//! "defs": {
64//! "colorName": "#hexcode"
65//! },
66//! "theme": {
67//! "primary": { "dark": "colorName", "light": "colorName" },
68//! "error": "#ff0000"
69//! }
70//! }
71//! ```
72//!
73//! # Usage with Widgets
74//!
75//! ```rust,no_run
76//! use ratatui::style::Style;
77//! use ratatui_toolkit::services::theme::AppTheme;
78//!
79//! let theme = AppTheme::default();
80//!
81//! // Use UI colors
82//! let primary_style = Style::default().fg(theme.primary);
83//! let error_style = Style::default().fg(theme.error);
84//!
85//! // Use diff colors
86//! let added_style = Style::default().fg(theme.diff.added);
87//!
88//! // Use markdown colors
89//! let heading_style = Style::default().fg(theme.markdown.heading);
90//! ```
91
92pub mod app_theme;
93pub mod diff_colors;
94pub mod loader;
95pub mod markdown_colors;
96pub mod persistence;
97pub mod syntax_colors;
98pub mod theme_variant;
99
100// Re-export main types at module level
101pub use app_theme::AppTheme;
102pub use diff_colors::DiffColors;
103pub use markdown_colors::MarkdownColors;
104pub use syntax_colors::SyntaxColors;
105pub use theme_variant::ThemeVariant;