Raxol.Terminal.Theme.Manager (Raxol Terminal v2.6.0)

Copy Markdown View Source

Manages terminal themes with advanced features:

  • Theme loading from files and presets
  • Theme customization and modification
  • Dynamic theme switching
  • Theme persistence and state management

Unified Theme System

Themes are sourced from Raxol.Core.Theming.ThemeRegistry, which provides a single source of truth for all Raxol themes. Use load_from_registry/2 to load any registered theme.

Usage

manager = Raxol.Terminal.Theme.Manager.new()

# Load a theme from the unified registry
{:ok, manager} = Raxol.Terminal.Theme.Manager.load_from_registry(manager, :dracula)

# Get a style
{:ok, style, manager} = Raxol.Terminal.Theme.Manager.get_style(manager, :normal)

Summary

Functions

Adds a custom style to the current theme.

Gets the current theme metrics.

Gets a style from the current theme or custom styles.

Lists all themes available in the unified registry.

Loads a theme from the unified theme registry.

Loads a theme from a file or preset.

Creates a new theme manager with the given options.

Restores a theme state from saved data.

Saves the current theme state for persistence.

Types

color()

@type color() :: %{r: integer(), g: integer(), b: integer(), a: float()}

style()

@type style() :: %{
  foreground: color(),
  background: color(),
  bold: boolean(),
  italic: boolean(),
  underline: boolean()
}

t()

@type t() :: %Raxol.Terminal.Theme.Manager{
  current_theme: theme(),
  custom_styles: %{required(String.t()) => style()},
  metrics: %{
    theme_switches: integer(),
    style_applications: integer(),
    customizations: integer(),
    load_operations: integer()
  },
  themes: %{required(String.t()) => theme()}
}

theme()

@type theme() :: %{
  name: String.t(),
  description: String.t(),
  author: String.t(),
  version: String.t(),
  colors: %{
    background: color(),
    foreground: color(),
    cursor: color(),
    selection: color(),
    black: color(),
    red: color(),
    green: color(),
    yellow: color(),
    blue: color(),
    magenta: color(),
    cyan: color(),
    white: color(),
    bright_black: color(),
    bright_red: color(),
    bright_green: color(),
    bright_yellow: color(),
    bright_blue: color(),
    bright_magenta: color(),
    bright_cyan: color(),
    bright_white: color()
  },
  styles: %{
    normal: style(),
    bold: style(),
    italic: style(),
    underline: style(),
    cursor: style(),
    selection: style()
  }
}

Functions

add_custom_style(manager, name, style)

@spec add_custom_style(t(), String.t(), style()) :: {:ok, t()} | {:error, term()}

Adds a custom style to the current theme.

get_metrics(manager)

@spec get_metrics(t()) :: map()

Gets the current theme metrics.

get_style(manager, style_name)

@spec get_style(t(), String.t() | atom()) :: {:ok, style(), t()} | {:error, term()}

Gets a style from the current theme or custom styles.

list_registry_themes()

@spec list_registry_themes() :: [atom()]

Lists all themes available in the unified registry.

load_from_registry(manager, theme_name)

@spec load_from_registry(t(), atom()) :: {:ok, t()} | {:error, :theme_not_found}

Loads a theme from the unified theme registry.

This is the preferred way to load themes as it uses the single source of truth for all Raxol theme definitions.

Examples

{:ok, manager} = Manager.load_from_registry(manager, :dracula)
{:ok, manager} = Manager.load_from_registry(manager, :synthwave84)

load_theme(manager, theme_name)

@spec load_theme(t(), String.t()) :: {:ok, t()} | {:error, term()}

Loads a theme from a file or preset.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new theme manager with the given options.

restore_theme_state(manager, state)

@spec restore_theme_state(t(), map()) :: {:ok, t()} | {:error, term()}

Restores a theme state from saved data.

save_theme_state(manager)

@spec save_theme_state(t()) :: {:ok, map()}

Saves the current theme state for persistence.