Breeze.Theme (Breeze v0.4.0)

Copy Markdown View Source

Theme helpers for semantic Breeze color tokens.

Themes can be:

  • :system16 for legacy ANSI-slot-based themes
  • :system for richer themes derived from the terminal palette when available
  • custom maps/keywords/structs with explicit defaults, palette entries, and extras

Theme variables

Color classes such as text-primary, bg-panel, border-warning, scrollbar-muted, and placeholder-text-muted resolve their suffix through the active theme. Inline style values such as %{foreground_color: :primary} use the same lookup.

Every built-in theme provides these default variables:

VariableAliasesIntended use
textfg, foreground_colorDefault foreground text
backgroundbg, background_colorDefault application background
borderstroke, border_colorDefault border and outline color

The bare text and bg classes select the default text and background colors. The aliases can also be used as suffixes, such as text-fg or bg-bg.

Every built-in theme also provides this semantic palette:

VariableIntended use
mutedSecondary text, subdued borders, and low-emphasis content
primaryPrimary actions, active controls, and prominent highlights
secondarySupporting actions and alternate highlights
warningCautionary states that need attention
errorErrors, failures, and destructive actions
successSuccessful and positive states
accentSelection, emphasis, and decorative highlights
surfaceRaised or subtly separated surfaces
panelPanels, dialogs, and stronger container backgrounds

Built-in themes define cursor as an extra variable for text input and textarea cursors. Inputs fall back to accent when a custom theme does not provide it.

Custom themes can override the standard variables and add any number of application-specific variables through extras:

Breeze.Theme.new(
  name: "brand",
  defaults: %{
    text: "#E8EEF7",
    background: "#10151D",
    border: "#52606D"
  },
  palette: %{
    muted: "#9AA5B1",
    primary: "#4DA3FF",
    secondary: "#9B8AFB",
    warning: "#F7C948",
    error: "#EF4E4E",
    success: "#3EBD93",
    accent: "#F970C7",
    surface: "#1B2430",
    panel: "#253244"
  },
  extras: %{cursor: "#FFFFFF", brand: "#4DA3FF"}
)

The custom brand variable is then available as text-brand, bg-brand, border-brand, and anywhere else Breeze resolves a color.

The variables field on %Breeze.Theme{} stores runtime theme metadata; it is not part of semantic color lookup. Named colors are resolved from defaults, palette, and extras, in that order.

Built-in themes

Pass these names to builtin/2:

  • :nebula
  • :catppuccin or :catppuccin with the :dark variant
  • :dracula
  • :gruvbox or :gruvbox with the :dark variant
  • :nord
  • :solarized with either the :light or :dark variant
  • :solarized_light and :solarized_dark as variant aliases

Summary

Types

A terminal color index, RGB tuple, or color string.

An RGB color tuple.

t()

A normalized Breeze theme.

Colors reported by a terminal palette probe.

Functions

Blends two colors using a weight clamped between 0.0 and 1.0.

Returns whether a theme supports RGB color blending.

Returns a built-in theme.

Returns a named default, palette, or extra color from a theme.

Darkens a color by blending it toward black.

Returns the default system-16 theme.

Returns the built-in theme names in their standard cycling order.

Returns the default style map for a theme input.

Returns whether a theme input enables theme-provided default styles.

Ensures an asynchronous terminal-palette probe is running.

Stores a completed runtime palette and returns its availability status.

Lightens a color by blending it toward white.

Merges terminal response data into an in-progress palette probe.

Normalizes a theme name, map, keyword list, or struct into a theme.

Returns the theme after current in a cycle, wrapping at the end.

Restores :system as the source for a system theme using a fallback palette.

Returns the terminal-palette probe status recorded by a theme.

Returns whether a theme input requests the terminal-derived system theme.

Resolves a semantic color name while preserving literal color values.

Resolves a built-in name or {name, theme} entry into a named theme tuple.

Returns whether a palette probe has collected all required colors.

Returns the terminal-palette probe timeout in milliseconds.

Starts a terminal-palette probe and returns its initial state.

Builds a theme from the terminal's standard 16-color palette.

Builds a theme from the terminal palette.

Types

color()

@type color() :: non_neg_integer() | rgb() | String.t()

A terminal color index, RGB tuple, or color string.

rgb()

@type rgb() :: {0..255, 0..255, 0..255}

An RGB color tuple.

t()

@type t() :: %Breeze.Theme{
  dark: boolean() | nil,
  defaults: %{optional(atom()) => color()},
  extras: %{optional(atom()) => color()},
  mode: :custom | :system | :system16,
  name: String.t() | nil,
  palette: %{optional(atom()) => color()},
  terminal_palette: terminal_palette() | nil,
  variables: %{optional(String.t()) => term()}
}

A normalized Breeze theme.

terminal_palette()

@type terminal_palette() :: %{optional(integer() | atom()) => color()}

Colors reported by a terminal palette probe.

Functions

blend(left, right, weight)

@spec blend(color(), color(), float()) :: color()

Blends two colors using a weight clamped between 0.0 and 1.0.

blendable?(theme)

@spec blendable?(t() | map() | keyword() | atom() | nil) :: boolean()

Returns whether a theme supports RGB color blending.

builtin(name, variant \\ nil)

@spec builtin(atom(), atom() | nil) :: t()

Returns a built-in theme.

The available themes are:

  • :nebula
  • :catppuccin or :catppuccin with the :dark variant
  • :dracula
  • :gruvbox or :gruvbox with the :dark variant
  • :nord
  • :solarized with either the :light or :dark variant
  • :solarized_light and :solarized_dark as variant aliases

Examples

Breeze.Theme.builtin(:nebula)
Breeze.Theme.builtin(:solarized, :light)

color(theme, key)

@spec color(t() | map() | keyword() | atom() | nil, atom() | String.t()) ::
  color() | nil

Returns a named default, palette, or extra color from a theme.

darken(color, amount)

@spec darken(color(), float()) :: color()

Darkens a color by blending it toward black.

default(opts \\ [])

@spec default(keyword()) :: t()

Returns the default system-16 theme.

default_cycle()

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

Returns the built-in theme names in their standard cycling order.

default_style(theme)

@spec default_style(t() | map() | keyword() | atom() | nil) :: map()

Returns the default style map for a theme input.

defaults_enabled?(theme)

@spec defaults_enabled?(term()) :: boolean()

Returns whether a theme input enables theme-provided default styles.

ensure_runtime_palette_async(terminal, notify_pid)

@spec ensure_runtime_palette_async(
  %Termite.Terminal{adapter: term(), reader: term(), size: term()} | nil,
  pid()
) :: :ok

Ensures an asynchronous terminal-palette probe is running.

finish_runtime_palette_probe(terminal, palette)

@spec finish_runtime_palette_probe(
  %Termite.Terminal{adapter: term(), reader: term(), size: term()} | nil,
  map()
) :: :ready | :unavailable

Stores a completed runtime palette and returns its availability status.

lighten(color, amount)

@spec lighten(color(), float()) :: color()

Lightens a color by blending it toward white.

merge_runtime_palette_data(buffer, palette, data)

@spec merge_runtime_palette_data(binary(), map(), binary()) :: {map(), binary()}

Merges terminal response data into an in-progress palette probe.

new(theme, opts \\ [])

@spec new(t() | map() | keyword() | atom() | nil, keyword()) :: t()

Normalizes a theme name, map, keyword list, or struct into a theme.

next_theme(current, themes \\ default_cycle())

@spec next_theme(term(), [atom() | {term(), term()}]) :: {term(), term()} | nil

Returns the theme after current in a cycle, wrapping at the end.

normalize_requested_source(theme)

@spec normalize_requested_source(term()) :: term()

Restores :system as the source for a system theme using a fallback palette.

probe_status(theme)

@spec probe_status(t() | map() | keyword() | atom() | nil) ::
  :ready | :pending | :unavailable | nil

Returns the terminal-palette probe status recorded by a theme.

requested_system?(theme)

@spec requested_system?(term()) :: boolean()

Returns whether a theme input requests the terminal-derived system theme.

resolve_color(theme, value)

@spec resolve_color(t() | map() | keyword() | atom() | nil, term()) :: term()

Resolves a semantic color name while preserving literal color values.

resolve_theme(name)

@spec resolve_theme(atom() | {term(), term()}) :: {term(), term()}

Resolves a built-in name or {name, theme} entry into a named theme tuple.

runtime_palette_probe_complete?(palette)

@spec runtime_palette_probe_complete?(map()) :: boolean()

Returns whether a palette probe has collected all required colors.

runtime_palette_probe_timeout_ms()

@spec runtime_palette_probe_timeout_ms() :: pos_integer()

Returns the terminal-palette probe timeout in milliseconds.

start_runtime_palette_probe(terminal)

@spec start_runtime_palette_probe(
  %Termite.Terminal{adapter: term(), reader: term(), size: term()}
  | nil
) :: {:start, term(), binary()} | :ready | :pending | :unavailable | :error

Starts a terminal-palette probe and returns its initial state.

system16(opts \\ [])

@spec system16(keyword()) :: t()

Builds a theme from the terminal's standard 16-color palette.

system(opts \\ [])

@spec system(keyword()) :: t()

Builds a theme from the terminal palette.

Falls back to system16/1 while retaining the system-theme request when a complete palette is not yet available.