Tuix.Color (tuix v0.1.0)

Copy Markdown View Source

Color parsing and SGR code generation.

Accepted color inputs:

  • Hex strings: "#FF8800" or "#f80"
  • RGB tuples: {255, 136, 0}
  • Named atoms: :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white and their :bright_* variants
  • nil for the terminal default

Summary

Functions

Returns the SGR codes (a list of integers) for a color in the given layer (:fg or :bg). Returns [] for nil.

Types

t()

@type t() :: nil | atom() | String.t() | {0..255, 0..255, 0..255}

Functions

to_sgr(name, layer)

@spec to_sgr(t(), :fg | :bg) :: [non_neg_integer()]

Returns the SGR codes (a list of integers) for a color in the given layer (:fg or :bg). Returns [] for nil.

Examples

iex> Tuix.Color.to_sgr("#FF8800", :fg)
[38, 2, 255, 136, 0]

iex> Tuix.Color.to_sgr(:red, :bg)
[41]

iex> Tuix.Color.to_sgr(nil, :fg)
[]