Raxol.Terminal.Color.TrueColor.AnsiCodes (Raxol Terminal v2.6.0)

Copy Markdown View Source

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

format_hex(r, g, b, a)

Formats an RGB(A) tuple as a hex string (e.g. "#FF0000" or "#FF0000AA").

pad(value)

Pads an integer to a 2-char uppercase hex string.

parse_hex_3(hex)

Parses a 3-char hex string to {:ok, r, g, b, 255} or {:error, :invalid_hex}.

parse_hex_4(hex)

Parses a 4-char hex string to {:ok, r, g, b, a} or {:error, :invalid_hex}.

parse_hex_6(hex)

Parses a 6-char hex string to {:ok, {r, g, b}} or {:error, :invalid_hex}.

parse_hex_8(hex)

Parses an 8-char hex string to {:ok, r, g, b, a} or {:error, :invalid_hex}.

to_16(r, g, b)

@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).

to_256(r, g, b)

@spec to_256(0..255, 0..255, 0..255) :: 0..255

Maps an 8-bit RGB color to a 256-color palette index.