Module loader

Module loader 

Source
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 from defs)
  • 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§

ThemeJson
Root structure of an opencode theme JSON file.

Enums§

ColorValue
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 AppTheme from a JSON file path.
load_theme_str
Loads an AppTheme from 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.