pub enum Color {
}Expand description
Terminal color definitions.
Supports both standard 16-color palette and 24-bit RGB colors.
§Color Palette
Standard colors (0-7):
Black Red Green Yellow
Blue Magenta Cyan WhiteBright colors (8-15):
BrightBlack BrightRed BrightGreen BrightYellow
BrightBlue BrightMagenta BrightCyan BrightWhiteVariants§
Black
Standard black (color 0)
Red
Standard red (color 1)
Green
Standard green (color 2)
Yellow
Standard yellow (color 3)
Blue
Standard blue (color 4)
Magenta
Standard magenta (color 5)
Cyan
Standard cyan (color 6)
White
Standard white (color 7)
BrightBlack
Bright black / dark gray (color 8)
BrightRed
Bright red (color 9)
BrightGreen
Bright green (color 10)
BrightYellow
Bright yellow (color 11)
BrightBlue
Bright blue (color 12)
BrightMagenta
Bright magenta (color 13)
BrightCyan
Bright cyan (color 14)
BrightWhite
Bright white (color 15)
Rgb(u8, u8, u8)
24-bit RGB color (requires terminal support)
Implementations§
Source§impl Color
impl Color
Sourcepub fn from_hex(hex: &str) -> Result<Self, &'static str>
pub fn from_hex(hex: &str) -> Result<Self, &'static str>
Creates a Color from a hex string.
Supports multiple formats:
- 1 digit:
"F"or"#F"→ grayscale RGB(255, 255, 255) - 3 digits:
"F53"or"#F53"→ RGB(255, 85, 51) - 6 digits:
"FF5733"or"#FF5733"→ RGB(255, 87, 51)
The # prefix is optional. Parsing is case-insensitive.
§Examples
let white = Color::from_hex("#F")?; // RGB(255, 255, 255)
let gray = Color::from_hex("8")?; // RGB(136, 136, 136)
let red = Color::from_hex("#F00")?; // RGB(255, 0, 0)
let orange = Color::from_hex("#FF5733")?; // RGB(255, 87, 51)Sourcepub fn hex(hex: &str) -> Self
pub fn hex(hex: &str) -> Self
Creates a Color from a hex string, panicking on invalid input.
This is a convenience method for use with compile-time constants where you know the hex string is valid.
§Examples
const BRAND_COLOR: Color = Color::hex("#FF5733");
const WHITE: Color = Color::hex("F");§Panics
Panics if the hex string is invalid.