ratatui_toolkit/services/theme/loader/
mod.rs

1//! Theme loader module for parsing opencode theme JSON files.
2//!
3//! This module provides functionality to load themes from JSON files in the
4//! opencode theme format, which uses a `defs` section for named color definitions
5//! and a `theme` section with semantic color mappings.
6//!
7//! # JSON Format
8//!
9//! The opencode theme format consists of:
10//!
11//! ```json
12//! {
13//!   "defs": {
14//!     "colorName": "#hexcode",
15//!     ...
16//!   },
17//!   "theme": {
18//!     "primary": { "dark": "colorName", "light": "colorName" },
19//!     "error": "#ff0000",
20//!     ...
21//!   }
22//! }
23//! ```
24//!
25//! # Resolution
26//!
27//! Color values in the `theme` section can be:
28//! - Direct hex colors: `"#ff0000"`
29//! - References to defs: `"colorName"` (resolved from `defs`)
30//! - Variant objects: `{ "dark": "value", "light": "value" }`
31//!
32//! # Example
33//!
34//! ```rust,no_run
35//! use ratatui_toolkit::services::theme::{loader, ThemeVariant, AppTheme};
36//!
37//! // Load from file path
38//! let theme = loader::load_theme_file("themes/gruvbox.json", ThemeVariant::Dark)
39//!     .expect("Failed to load theme");
40//!
41//! // Load from JSON string
42//! let json = r#"{"defs": {"bg": "#282828"}, "theme": {"background": "bg"}}"#;
43//! let theme = loader::load_theme_str(json, ThemeVariant::Dark)
44//!     .expect("Failed to parse theme");
45//! ```
46
47mod load_builtin;
48mod load_theme_file;
49mod load_theme_str;
50mod parse_color;
51mod resolve_defs;
52mod theme_json;
53
54pub use load_builtin::{load_builtin_theme, BUILTIN_THEMES};
55pub use load_theme_file::load_theme_file;
56pub use load_theme_str::load_theme_str;
57pub use parse_color::parse_hex_color;
58pub use resolve_defs::resolve_color_value;
59pub use theme_json::{ColorValue, ThemeJson};