Raxol.LiveView.Themes (Raxol v2.0.1)

View Source

Built-in theme system for Raxol web terminals.

Provides curated terminal color schemes optimized for readability and aesthetics in web browsers.

Usage

# Get a built-in theme
{:ok, theme} = Raxol.LiveView.Themes.get_theme(:synthwave84)

# Or use the unsafe version (returns theme or default)
theme = Raxol.LiveView.Themes.get(:synthwave84)

# Validate a custom theme
case Raxol.LiveView.Themes.validate_theme(custom_theme) do
  :ok -> # theme is valid
  {:error, reason} -> # handle error
end

# Generate CSS for a theme
css = Raxol.LiveView.Themes.to_css(theme)

# List available themes
themes = Raxol.LiveView.Themes.list()

Summary

Functions

Returns a built-in theme by name, or nil if not found.

Returns a built-in theme by name.

Lists all available theme names.

Validates a theme structure.

Types

theme()

@type theme() :: %{
  name: atom(),
  background: String.t(),
  foreground: String.t(),
  cursor: String.t(),
  selection: String.t(),
  colors: %{
    black: String.t(),
    red: String.t(),
    green: String.t(),
    yellow: String.t(),
    blue: String.t(),
    magenta: String.t(),
    cyan: String.t(),
    white: String.t(),
    bright_black: String.t(),
    bright_red: String.t(),
    bright_green: String.t(),
    bright_yellow: String.t(),
    bright_blue: String.t(),
    bright_magenta: String.t(),
    bright_cyan: String.t(),
    bright_white: String.t()
  }
}

Functions

get(name)

@spec get(atom()) :: theme() | nil

Returns a built-in theme by name, or nil if not found.

For a version that returns {:ok, theme} | {:error, reason}, use get_theme/1.

get_theme(name)

@spec get_theme(atom()) :: {:ok, theme()} | {:error, :theme_not_found}

Returns a built-in theme by name.

Returns {:ok, theme} on success or {:error, :theme_not_found} if the theme doesn't exist.

list()

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

Lists all available theme names.

to_css(theme, selector \\ ".raxol-terminal")

@spec to_css(theme(), String.t()) :: String.t()

Generates CSS for a theme.

Returns CSS as a string that can be injected into a page or style tag. If the theme is invalid, returns minimal fallback CSS and logs a warning.

validate_theme(arg1)

@spec validate_theme(any()) :: :ok | {:error, atom()}

Validates a theme structure.

Returns :ok if valid, or {:error, reason} if invalid.