Color model supporting 16 standard ANSI colors, 256 indexed palette, and 24-bit TrueColor RGB.
Constructors
Constructs Color from CMYK components: C, M, Y, K in [0, 1]
SourceResolves a symbol or string (e.g. :red, "#ff0000", "blue") into a Color
SourceParses hex string like "#ff79c6", "61AFEF", or "#fff"
SourceConstructs Color from HSL components: h in [0, 360], s in [0, 1], l in [0, 1]
SourceConstructs Color from HSV components: h in [0, 360], s in [0, 1], v in [0, 1]
SourceConstructs Color from CIELAB components: L* in [0, 100], a* in [-128, 127], b* in [-128, 127]
Sourcelerp(c1 :
Color, c2 :
Color, t :
Float64) :
Color Linearly interpolates between two colors by factor t (0.0 to 1.0)
SourceConstructs Color from Oklab components: L in [0, 1], a in [-0.4, 0.4], b in [-0.4, 0.4]
SourceConstructs Color from Oklch components: L in [0, 1], C in [0, 0.4], h in [0, 360]
SourceConstructs Color from CIE XYZ components: X, Y, Z in [0, 1]
SourceClass methods
no_color?
Checks whether colors are suppressed via NO_COLOR standard
SourceInstance methods
bg_escape
Emits the ANSI escape code for background
Sourcecontrast_ratio(other :
Color) :
Float64 Calculates WCAG 2.1 contrast ratio against another color (range 1.0 : 1 to 21.0 : 1)
SourceDarkens the color toward black by factor (0.0 to 1.0)
Sourceensure_contrast(bg :
Color, min_ratio :
Float64 = 4.5) :
Color Adjusts luminance until contrast ratio against bg meets or exceeds min_ratio
Sourcefg_escape
Emits the ANSI escape code for foreground
SourceLightens the color toward white by factor (0.0 to 1.0)
Sourcereadable_against?(bg :
Color, min_ratio :
Float64 = 4.5) :
Bool Returns true if the contrast ratio meets or exceeds the required WCAG threshold (default 4.5 for AA normal text)
Sourcerelative_luminance
Calculates WCAG 2.1 relative luminance (0.0 for black to 1.0 for white)
Sourceto_cmyk
Converts Color to CMYK components: {C, M, Y, K} in [0..1]
Sourceto_hex
Formats color as hex string "#RRGGBB"
Sourceto_hsl
Converts Color to HSL components: {H [0..360], S [0..1], L [0..1]}
Sourceto_hsv
Converts Color to HSV components: {H [0..360], S [0..1], V [0..1]}
Sourceto_lab
Converts Color to CIELAB components: {L* [0..100], a* [-128..127], b* [-128..127]}
Sourceto_oklab
Converts Color to Oklab components: {L [0..1], a [-0.4..0.4], b [-0.4..0.4]}
Sourceto_oklch
Converts Color to Oklch components: {L [0..1], C [0..0.4], h [0..360]}
Sourceto_rgb
Converts color to RGB tuple (approximate for ANSI)
Sourceto_xyz
Converts Color to CIE XYZ components: {X, Y, Z} in [0..1]
Sourcewrite_bg_escape(io :
IO) :
Nil Writes background ANSI escape sequence directly to an IO without intermediate String allocations
Sourcewrite_fg_escape(io :
IO) :
Nil Writes foreground ANSI escape sequence directly to an IO without intermediate String allocations
Source