Expand description
Variants
ForegroundColor(Color)
A foreground color.
BackgroundColor(Color)
A background color.
Implementations
sourceimpl 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
sourceimpl Ord for Colored
impl Ord for Colored
sourceimpl PartialOrd<Colored> for Colored
impl PartialOrd<Colored> for Colored
sourcefn partial_cmp(&self, other: &Colored) -> Option<Ordering>
fn partial_cmp(&self, other: &Colored) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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
impl Copy for Colored
impl Eq for Colored
impl StructuralEq for Colored
impl StructuralPartialEq for Colored
Auto Trait Implementations
impl RefUnwindSafe for Colored
impl Send for Colored
impl Sync for Colored
impl Unpin for Colored
impl UnwindSafe for Colored
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more