pub enum Colored {
ForegroundColor(Color),
BackgroundColor(Color),
UnderlineColor(Color),
}
Expand description
Variants§
ForegroundColor(Color)
A foreground color.
BackgroundColor(Color)
A background color.
UnderlineColor(Color)
An underline color. Imporant: doesnt work on windows 10 or lower.
Implementations§
source§impl Colored
impl Colored
sourcepub fn parse_ansi(ansi: &str) -> Option<Self>
pub fn parse_ansi(ansi: &str) -> Option<Self>
Parse an ANSI foreground or background color.
This is the string that would appear within an ESC [ <str> m
escape sequence, as found in
various configuration files.
Examples
use crossterm::style::{Colored::{self, ForegroundColor, BackgroundColor}, Color};
assert_eq!(Colored::parse_ansi("38;5;0"), Some(ForegroundColor(Color::Black)));
assert_eq!(Colored::parse_ansi("38;5;26"), Some(ForegroundColor(Color::AnsiValue(26))));
assert_eq!(Colored::parse_ansi("48;2;50;60;70"), Some(BackgroundColor(Color::Rgb { r: 50, g: 60, b: 70 })));
assert_eq!(Colored::parse_ansi("49"), Some(BackgroundColor(Color::Reset)));
assert_eq!(Colored::parse_ansi("invalid color"), None);
Currently, 3/4 bit color values aren’t supported so return None
.
See also: Color::parse_ansi
.
Trait Implementations§
source§impl Ord for Colored
impl Ord for Colored
source§impl PartialEq<Colored> for Colored
impl PartialEq<Colored> for Colored
source§impl PartialOrd<Colored> for Colored
impl PartialOrd<Colored> for Colored
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more