pub enum Color {
}Expand description
Color type supporting various color formats
Variants§
Reset
Default terminal color
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
BrightBlack
BrightRed
BrightGreen
BrightYellow
BrightBlue
BrightMagenta
BrightCyan
BrightWhite
Ansi256(u8)
256-color palette (0-255)
Rgb(u8, u8, u8)
RGB color (24-bit)
Implementations§
Source§impl Color
impl Color
Sourcepub fn hex(hex: &str) -> Color
pub fn hex(hex: &str) -> Color
Create a color from a hex string (e.g., “#ff0000” or “ff0000”)
Returns Color::Reset for invalid hex strings. Use try_hex for
explicit error handling.
§Examples
use rnk_style_core::Color;
// Valid hex codes
assert_eq!(Color::hex("#ff0000"), Color::Rgb(255, 0, 0));
assert_eq!(Color::hex("00ff00"), Color::Rgb(0, 255, 0));
// Invalid hex codes return Reset
assert_eq!(Color::hex("invalid"), Color::Reset);
assert_eq!(Color::hex("#fff"), Color::Reset); // 3-char not supportedSourcepub fn try_hex(hex: &str) -> Option<Color>
pub fn try_hex(hex: &str) -> Option<Color>
Try to create a color from a hex string, returning None on invalid input
§Examples
use rnk_style_core::Color;
assert_eq!(Color::try_hex("#ff0000"), Some(Color::Rgb(255, 0, 0)));
assert_eq!(Color::try_hex("invalid"), None);
assert_eq!(Color::try_hex("#gg0000"), None); // invalid hex charsSourcepub fn to_ansi_fg(&self) -> String
pub fn to_ansi_fg(&self) -> String
Convert to ANSI foreground escape code
§Examples
use rnk_style_core::Color;
assert_eq!(Color::Red.to_ansi_fg(), "\x1b[31m");
assert_eq!(Color::Rgb(255, 0, 0).to_ansi_fg(), "\x1b[38;2;255;0;0m");Sourcepub fn to_ansi_bg(&self) -> String
pub fn to_ansi_bg(&self) -> String
Convert to ANSI background escape code
§Examples
use rnk_style_core::Color;
assert_eq!(Color::Red.to_ansi_bg(), "\x1b[41m");
assert_eq!(Color::Rgb(255, 0, 0).to_ansi_bg(), "\x1b[48;2;255;0;0m");Trait Implementations§
impl Copy for Color
impl Eq for Color
Source§impl From<AdaptiveColor> for Color
impl From<AdaptiveColor> for Color
Source§fn from(adaptive: AdaptiveColor) -> Color
fn from(adaptive: AdaptiveColor) -> Color
Converts to this type from the input type.
Source§impl From<Color> for AdaptiveColor
impl From<Color> for AdaptiveColor
Source§fn from(color: Color) -> AdaptiveColor
fn from(color: Color) -> AdaptiveColor
Converts to this type from the input type.
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Forget for Color
impl Freeze for Color
impl Move for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnsafeUnpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more