ElixirOpentui.Color (ElixirOpentui v0.2.0)

Copy Markdown View Source

RGBA color representation for terminal UI rendering.

Colors are stored as 4-tuples {r, g, b, a} where each component is 0-255. Alpha channel is used for opacity/blending calculations.

Summary

Functions

Alpha-blend fg over bg. Standard Porter-Duff "source over" compositing.

Parse a hex color string like '#FF0000' or '#FF0000FF'.

Create an opaque RGB color from HSL values.

Create an RGB color with full opacity.

Create an RGBA color.

Convert to ANSI 24-bit background escape sequence.

Convert to ANSI 24-bit foreground escape sequence.

Apply opacity (0.0-1.0) to a color by scaling its alpha.

Types

component()

@type component() :: 0..255

t()

@type t() :: {component(), component(), component(), component()}

Functions

black()

blend(arg1, bg)

@spec blend(fg :: t(), bg :: t()) :: t()

Alpha-blend fg over bg. Standard Porter-Duff "source over" compositing.

blue()

from_hex(arg1)

@spec from_hex(String.t()) :: {:ok, t()} | {:error, :invalid_hex}

Parse a hex color string like '#FF0000' or '#FF0000FF'.

green()

hsl(h, s, l)

@spec hsl(number(), float(), float()) :: t()

Create an opaque RGB color from HSL values.

Hue is in degrees (0-360, wraps), saturation and lightness are 0.0-1.0. Returns an {r, g, b, 255} tuple.

red()

rgb(r, g, b)

@spec rgb(component(), component(), component()) :: t()

Create an RGB color with full opacity.

rgba(r, g, b, a)

@spec rgba(component(), component(), component(), component()) :: t()

Create an RGBA color.

to_ansi_bg(arg)

@spec to_ansi_bg(t()) :: iodata()

Convert to ANSI 24-bit background escape sequence.

to_ansi_fg(arg)

@spec to_ansi_fg(t()) :: iodata()

Convert to ANSI 24-bit foreground escape sequence.

transparent()

white()

with_opacity(arg, opacity)

@spec with_opacity(t(), float()) :: t()

Apply opacity (0.0-1.0) to a color by scaling its alpha.