Available on crate feature
theme only.Expand description
Theme loader module for parsing opencode theme JSON files.
This module provides functionality to load themes from JSON files in the
opencode theme format, which uses a defs section for named color definitions
and a theme section with semantic color mappings.
§JSON Format
The opencode theme format consists of:
{
"defs": {
"colorName": "#hexcode",
...
},
"theme": {
"primary": { "dark": "colorName", "light": "colorName" },
"error": "#ff0000",
...
}
}§Resolution
Color values in the theme section can be:
- Direct hex colors:
"#ff0000" - References to defs:
"colorName"(resolved fromdefs) - Variant objects:
{ "dark": "value", "light": "value" }
§Example
use ratatui_toolkit::services::theme::{loader, ThemeVariant, AppTheme};
// Load from file path
let theme = loader::load_theme_file("themes/gruvbox.json", ThemeVariant::Dark)
.expect("Failed to load theme");
// Load from JSON string
let json = r#"{"defs": {"bg": "#282828"}, "theme": {"background": "bg"}}"#;
let theme = loader::load_theme_str(json, ThemeVariant::Dark)
.expect("Failed to parse theme");Structs§
- Theme
Json - Root structure of an opencode theme JSON file.
Enums§
- Color
Value - Represents a color value in the theme JSON.
Constants§
- BUILTIN_
THEMES - Available builtin theme names.
Functions§
- load_
builtin_ theme - Loads a builtin theme by name.
- load_
theme_ file - Loads an
AppThemefrom a JSON file path. - load_
theme_ str - Loads an
AppThemefrom a JSON string in opencode format. - parse_
hex_ color - Parses a hex color string into a ratatui Color.
- resolve_
color_ value - Resolves a color value from the theme JSON, handling defs references.