Alaja.Theme (Alaja v2.2.0)

Copy Markdown View Source

Theme management facade for Alaja.

Generated by use Pote.Theme. Exposes the full Pote.Theme contract — list/0, active/0, activate/1, color/1, colors/0, install!/1, install_template/1, templates/0, register_with_pote/0 — wired up against the Alaja application's config + the ~/.config/alaja/themes storage directory.

Quick start

Alaja.Theme.list()             # => ["default", "dracula", ...]
Alaja.Theme.activate("dracula")
Alaja.Theme.color("primary")   # => {189, 147, 249}

Integration with Pote

Calling Alaja.Theme.register_with_pote/0 (or just ensure_registered/0, called lazily by every other function) registers a theme resolver on Pote's resolver stack so that Pote.parse("theme:<key>") consults the active Alaja theme. This is the mechanism that makes alaja separator --color "theme:ternary" resolve to the user's selected ternary colour, not a hardcoded default.

Storage directory

storage_dir/0 defaults to ~/.config/alaja/themes and honours the ALAJA_THEMES_PATH env var at runtime, so tests and downstream tools can redirect the directory without recompiling.

Summary

Functions

Activates a theme by name. Writes through to :theme_active.

Returns the active theme as a Pote.Theme.Theme struct.

Looks up a single colour key in the active theme.

Returns the colour map for the active theme.

Theme management facade for Alaja.Theme.

Installs a theme to disk. Accepts a Pote.Theme.Theme struct (or a name + map tuple via install_template/2).

Installs a built-in template theme by name.

Lists all themes available in storage_dir.

Registers the resolver with Pote so Pote.parse("theme:<key>") and atom lookups consult this theme system. Idempotent.

Returns the list of built-in template theme names.

Functions

activate(name)

@spec activate(String.t()) :: :ok

Activates a theme by name. Writes through to :theme_active.

active()

@spec active() :: Pote.Theme.Theme.t()

Returns the active theme as a Pote.Theme.Theme struct.

Reads :theme_active from the application's config, loads the JSON file, and returns the parsed theme. Falls back to the built-in default theme when no theme is selected or the active file is unreadable.

color(key)

@spec color(String.t()) ::
  {:ok, {non_neg_integer(), non_neg_integer(), non_neg_integer()}} | :not_found

Looks up a single colour key in the active theme.

Returns {:ok, {r, g, b}} on hit, :not_found on miss.

colors()

@spec colors() :: %{
  optional(String.t()) =>
    {non_neg_integer(), non_neg_integer(), non_neg_integer()}
}

Returns the colour map for the active theme.

config_app()

Theme management facade for Alaja.Theme.

Generated by use Pote.Theme. See Pote.Theme for the full contract.

install!(theme)

@spec install!(Pote.Theme.Theme.t()) :: :ok | {:error, term()}

Installs a theme to disk. Accepts a Pote.Theme.Theme struct (or a name + map tuple via install_template/2).

install_template(name)

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

Installs a built-in template theme by name.

Returns :ok if the template was installed, {:error, :not_found} if the template does not exist.

list()

@spec list() :: [String.t()]

Lists all themes available in storage_dir.

register_with_pote()

@spec register_with_pote() :: :ok

Registers the resolver with Pote so Pote.parse("theme:<key>") and atom lookups consult this theme system. Idempotent.

storage_dir()

templates()

@spec templates() :: [String.t()]

Returns the list of built-in template theme names.