Esc.Theme (Esc v0.9.0)

View Source

Theme definitions for terminal styling.

Themes provide a consistent color palette including:

  • 16 ANSI colors (ansi_0 through ansi_15)
  • Background and foreground colors
  • Semantic colors for common UI purposes

Semantic Colors

Semantic colors provide meaningful names for common use cases:

  • :header - Headers, titles (defaults to cyan/ansi_6)
  • :emphasis - Important text (defaults to blue/ansi_4)
  • :warning - Warning messages (defaults to yellow/ansi_3)
  • :error - Error messages (defaults to red/ansi_1)
  • :success - Success messages (defaults to green/ansi_2)
  • :muted - Subdued text, borders (defaults to bright black/ansi_8)

Usage

Esc.set_theme(:nord)

# Use semantic colors in styles
style() |> theme_foreground(:error) |> render("Error!")

Summary

Functions

Gets a color from a theme by name.

Types

rgb()

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

t()

@type t() :: %Esc.Theme{
  ansi_0: rgb(),
  ansi_1: rgb(),
  ansi_10: rgb(),
  ansi_11: rgb(),
  ansi_12: rgb(),
  ansi_13: rgb(),
  ansi_14: rgb(),
  ansi_15: rgb(),
  ansi_2: rgb(),
  ansi_3: rgb(),
  ansi_4: rgb(),
  ansi_5: rgb(),
  ansi_6: rgb(),
  ansi_7: rgb(),
  ansi_8: rgb(),
  ansi_9: rgb(),
  background: rgb(),
  emphasis: rgb() | nil,
  error: rgb() | nil,
  foreground: rgb(),
  header: rgb() | nil,
  muted: rgb() | nil,
  name: atom(),
  success: rgb() | nil,
  warning: rgb() | nil
}

Functions

color(theme, name)

@spec color(t(), atom()) :: rgb() | nil

Gets a color from a theme by name.

Handles both direct palette colors (ansi_0..ansi_15, background, foreground) and semantic colors (header, emphasis, warning, error, success, muted).

Semantic colors are derived from the ANSI palette if not explicitly set.

Examples

iex> theme = Esc.Theme.Palette.get(:nord)
iex> Esc.Theme.color(theme, :error)
{191, 97, 106}

iex> Esc.Theme.color(theme, :ansi_4)
{129, 161, 193}