Raxol.Style.Colors.Formats (Raxol v2.0.1)
View SourceColor format conversion utilities.
This module provides functions for converting between different color formats:
- RGB/RGBA tuples
- Hex strings
- ANSI color codes
- Named colors
Summary
Functions
Converts an ANSI color code to RGB values.
Parses a hex string into RGB/RGBA values.
Converts RGB values to an ANSI color code.
Converts a color to its hex representation.
Functions
Converts an ANSI color code to RGB values.
Examples
iex> Formats.ansi_to_rgb(1)
{205, 0, 0}
@spec from_hex(String.t()) :: {integer(), integer(), integer()} | {integer(), integer(), integer(), integer()}
Parses a hex string into RGB/RGBA values.
Examples
iex> Formats.from_hex("#FF0000")
{255, 0, 0}
iex> Formats.from_hex("#FF000080")
{255, 0, 0, 128}
@spec rgb_to_ansi({byte(), byte(), byte()}) :: pos_integer()
Converts RGB values to an ANSI color code.
Examples
iex> Formats.rgb_to_ansi({255, 0, 0})
196
Converts a color to its hex representation.
Examples
iex> Formats.to_hex({255, 0, 0})
"#FF0000"
iex> Formats.to_hex({255, 0, 0, 128})
"#FF000080"