Color orchestration module for parsing, converting, and formatting colors.
This module provides a unified interface for working with various color formats, converting between them, and generating ANSI escape codes.
Parsing logic is delegated to Pote.Orchestrator.Parser.
Supported Color Formats
- RGB tuples:
{r, g, b}where each value is 0-255 - Hex strings:
"#RRGGBB"or"RRGGBB" - HSL tuples:
{h, s, l}where h is 0-360°, s and l are 0-100% - HSV tuples:
{h, s, v}where h is 0-360°, s and v are 0-100% - CMYK tuples:
{c, m, y, k}where each value is 0-100% - XTerm256: Integer 0-255
- Atom colors:
:red,:green,:blue, etc. - Named colors:
"red","green","blue", etc.
Usage
iex> Pote.Orchestrator.parse_color("#FF8000")
{:ok, {255, 128, 0}}
iex> Pote.Orchestrator.to_ansi({255, 128, 0})
"\e[38;2;255;128;0m"
Summary
Functions
Returns the list of supported named colors.
Parses a color from various input formats.
Converts a color to its ANSI escape code for foreground.
Converts a color to its ANSI escape code for background.
Converts a color value to a Pote.ColorInfo struct.
Converts any color format to RGB tuple.
Converts any color format to RGB tuple (raises on error).
Converts a color to XTerm256 index.
Types
@type cmyk() :: Pote.cmyk()
@type color_input() :: Pote.color_input()
@type color_output() :: Pote.color_output()
@type hex() :: Pote.hex()
@type hsl() :: Pote.hsl()
@type hsv() :: Pote.hsv()
@type rgb() :: Pote.rgb()
@type xterm256() :: Pote.xterm256()
Functions
@spec named_colors() :: keyword()
Returns the list of supported named colors.
@spec parse_color(color_input()) :: {:ok, rgb()} | {:error, String.t()}
Parses a color from various input formats.
Delegates to Pote.Orchestrator.Parser.parse_color/1.
Parameters
input- Color in any supported format
Returns
{:ok, rgb}- RGB tuple on success{:error, message}- Error string with explanation
@spec to_ansi(color_input() | nil) :: String.t()
Converts a color to its ANSI escape code for foreground.
Parameters
input- Color in any supported format
Returns
- ANSI escape code string
@spec to_ansi_bg(color_input() | nil) :: String.t()
Converts a color to its ANSI escape code for background.
Parameters
input- Color in any supported format
Returns
- ANSI escape code string for background color
@spec to_color_info(atom() | String.t() | tuple()) :: Pote.ColorInfo.t()
Converts a color value to a Pote.ColorInfo struct.
@spec to_rgb(color_input()) :: {:ok, rgb()} | {:error, String.t()}
Converts any color format to RGB tuple.
Parameters
input- Color in any supported format
Returns
{:ok, rgb}- RGB tuple on success{:error, reason}- Error tuple if conversion fails
@spec to_rgb!(color_input()) :: rgb()
Converts any color format to RGB tuple (raises on error).
Parameters
input- Color in any supported format
Returns
- RGB tuple
@spec to_xterm256(color_input()) :: {:ok, xterm256()} | {:error, String.t()}
Converts a color to XTerm256 index.
Parameters
input- Color in any supported format
Returns
{:ok, xterm256}- XTerm256 index on success{:error, reason}- Error tuple if conversion fails