pub fn load_theme_str(
json: &str,
variant: ThemeVariant,
) -> Result<AppTheme, String>Available on crate feature
theme only.Expand description
Loads an AppTheme from a JSON string in opencode format.
Parses the JSON, resolves all color references, and constructs
a complete AppTheme with all color categories populated.
§Arguments
json- The JSON string to parsevariant- Which theme variant (dark/light) to use
§Returns
Ok(AppTheme) if parsing and resolution succeeds,
Err with a description if parsing fails.
§Errors
Returns an error if:
- The JSON is malformed
- Required color keys are missing
- Color values cannot be resolved
§Example
use ratatui_toolkit::services::theme::{loader, ThemeVariant};
let json = r#"{
"defs": { "bg": "#282828", "fg": "#ebdbb2" },
"theme": {
"background": "bg",
"text": "fg"
}
}"#;
let theme = loader::load_theme_str(json, ThemeVariant::Dark);
assert!(theme.is_ok());