Packages

Declarative CLI framework and terminal rendering kit for Elixir — commands DSL, auto-generated help, ANSI rendering, tables, headers, boxes, and interactive prompts.

Current section

Files

Jump to
alaja lib alaja theme.ex
Raw

lib/alaja/theme.ex

defmodule Alaja.Theme do
@moduledoc """
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.
"""
use Pote.Theme,
config_app: :alaja,
defaults: %{}
# Override the storage_dir generated by `use Pote.Theme` so it honours
# the ALAJA_THEMES_PATH env var at runtime. Marked defoverridable by
# the macro, so this definition wins.
def storage_dir, do: System.get_env("ALAJA_THEMES_PATH") || default_themes_path()
defp default_themes_path do
Path.join([System.user_home!(), ".config", "alaja", "themes"])
end
end