Low-level ANSI color code helpers: 256-color and 16-color mapping, hex string parsing, and hex formatting.
Summary
Functions
Formats an RGB(A) tuple as a hex string (e.g. "#FF0000" or "#FF0000AA").
Pads an integer to a 2-char uppercase hex string.
Parses a 3-char hex string to {:ok, r, g, b, 255} or {:error, :invalid_hex}.
Parses a 4-char hex string to {:ok, r, g, b, a} or {:error, :invalid_hex}.
Parses a 6-char hex string to {:ok, {r, g, b}} or {:error, :invalid_hex}.
Parses an 8-char hex string to {:ok, r, g, b, a} or {:error, :invalid_hex}.
Maps an 8-bit RGB color to the nearest 16-color ANSI code (foreground).
Maps an 8-bit RGB color to a 256-color palette index.
Functions
Formats an RGB(A) tuple as a hex string (e.g. "#FF0000" or "#FF0000AA").
Pads an integer to a 2-char uppercase hex string.
Parses a 3-char hex string to {:ok, r, g, b, 255} or {:error, :invalid_hex}.
Parses a 4-char hex string to {:ok, r, g, b, a} or {:error, :invalid_hex}.
Parses a 6-char hex string to {:ok, {r, g, b}} or {:error, :invalid_hex}.
Parses an 8-char hex string to {:ok, r, g, b, a} or {:error, :invalid_hex}.
@spec to_16(0..255, 0..255, 0..255) :: 30..97
Maps an 8-bit RGB color to the nearest 16-color ANSI code (foreground).
@spec to_256(0..255, 0..255, 0..255) :: 0..255
Maps an 8-bit RGB color to a 256-color palette index.