pub enum Color {
Reset,
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
Rgb(u8, u8, u8),
Indexed(u8),
}Expand description
Terminal color.
Covers the standard 16 named colors, 256-color palette indices, and
24-bit RGB true color. Use Color::Reset to restore the terminal’s
default foreground or background.
Variants§
Reset
Reset to the terminal’s default color.
Black
Standard black (color index 0).
Red
Standard red (color index 1).
Green
Standard green (color index 2).
Yellow
Standard yellow (color index 3).
Blue
Standard blue (color index 4).
Magenta
Standard magenta (color index 5).
Cyan
Standard cyan (color index 6).
White
Standard white (color index 7).
Rgb(u8, u8, u8)
24-bit true color.
Indexed(u8)
256-color palette index.
Implementations§
Source§impl Color
impl Color
Sourcepub fn luminance(self) -> f32
pub fn luminance(self) -> f32
Compute relative luminance using ITU-R BT.709 coefficients.
Returns a value in [0.0, 1.0] where 0 is darkest and 1 is brightest.
Use this to determine whether text on a given background should be
light or dark.
§Example
use slt::Color;
let dark = Color::Rgb(30, 30, 46);
assert!(dark.luminance() < 0.15);
let light = Color::Rgb(205, 214, 244);
assert!(light.luminance() > 0.6);Sourcepub fn contrast_fg(bg: Color) -> Color
pub fn contrast_fg(bg: Color) -> Color
Return a contrasting foreground color for the given background.
Uses the BT.709 luminance threshold (0.5) to decide between white
and black text. For theme-aware contrast, prefer using this over
hardcoding theme.bg as the foreground.
§Example
use slt::Color;
let bg = Color::Rgb(189, 147, 249); // Dracula purple
let fg = Color::contrast_fg(bg);
// Purple is mid-bright → returns black for readable textSourcepub fn blend(self, other: Color, alpha: f32) -> Color
pub fn blend(self, other: Color, alpha: f32) -> Color
Blend this color over another with the given alpha.
alpha is in [0.0, 1.0] where 0.0 returns other unchanged and
1.0 returns self unchanged. Both colors are resolved to RGB.
§Example
use slt::Color;
let white = Color::Rgb(255, 255, 255);
let black = Color::Rgb(0, 0, 0);
let gray = white.blend(black, 0.5);
// ≈ Rgb(128, 128, 128)