pub struct Color256(pub u8);
Expand description
Colors in a 256-value (8-bit) palette
Constants are provided for the initial 16 colors.
Color256
values can be parsed from case-insensitive
names (see Color256::name()
) or from strings of the form
"color({index})"
.
Color256
values are displayed as their lowercase
names or, for colors without names, as strings of the form
"color({index})"
.
§Examples
use parse_style::Color256;
assert_eq!("color(2)".parse::<Color256>().unwrap(), Color256(2));
assert_eq!("green".parse::<Color256>().unwrap(), Color256(2));
assert_eq!("GREEN".parse::<Color256>().unwrap(), Color256(2));
assert_eq!(Color256(2).to_string(), "green");
assert_eq!(Color256(42).to_string(), "color(42)");
Tuple Fields§
§0: u8
Implementations§
Source§impl Color256
impl Color256
Sourcepub const BRIGHT_BLACK: Color256
pub const BRIGHT_BLACK: Color256
Color 8, also known as “dark grey” or “grey”
Sourcepub const BRIGHT_RED: Color256
pub const BRIGHT_RED: Color256
Color 9
Sourcepub const BRIGHT_GREEN: Color256
pub const BRIGHT_GREEN: Color256
Color 10
Sourcepub const BRIGHT_YELLOW: Color256
pub const BRIGHT_YELLOW: Color256
Color 11
Sourcepub const BRIGHT_BLUE: Color256
pub const BRIGHT_BLUE: Color256
Color 12
Sourcepub const BRIGHT_MAGENTA: Color256
pub const BRIGHT_MAGENTA: Color256
Color 13
Sourcepub const BRIGHT_CYAN: Color256
pub const BRIGHT_CYAN: Color256
Color 14
Sourcepub const BRIGHT_WHITE: Color256
pub const BRIGHT_WHITE: Color256
Color 15, also known as “white”
Sourcepub fn name(self) -> Option<&'static str>
pub fn name(self) -> Option<&'static str>
Return the lowercase name of the color as recognized by rich
. See
this page for the list of color names.
Note that not all colors have a name. Also note that some greyscale colors have two names, one using the spelling “gray” and the other “grey”; this method uses the “gray” spellings.
§Examples
use parse_style::Color256;
assert_eq!(Color256::BRIGHT_YELLOW.name(), Some("bright_yellow"));
assert_eq!(Color256(42).name(), None);
assert_eq!(Color256(59).name(), Some("gray37"));
assert_eq!(Color256(118).name(), Some("chartreuse1"));
Sourcepub fn as_foreground(self) -> Style
pub fn as_foreground(self) -> Style
Return a new Style
that uses this color as the foreground color
Sourcepub fn as_background(self) -> Style
pub fn as_background(self) -> Style
Return a new Style
that uses this color as the background color
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Color256
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Color256
serde
only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl From<Ansi256Color> for Color256
Available on crate feature anstyle
only.
impl From<Ansi256Color> for Color256
anstyle
only.Source§fn from(value: Ansi256Color) -> Color256
fn from(value: Ansi256Color) -> Color256
Convert an anstyle::Ansi256Color
to a Color256
Source§impl From<Color256> for Ansi256Color
Available on crate feature anstyle
only.
impl From<Color256> for Ansi256Color
anstyle
only.Source§fn from(value: Color256) -> Ansi256Color
fn from(value: Color256) -> Ansi256Color
Convert a Color256
to an anstyle::Ansi256Color
Source§impl Ord for Color256
impl Ord for Color256
Source§impl PartialOrd for Color256
impl PartialOrd for Color256
impl Copy for Color256
impl Eq for Color256
impl StructuralPartialEq for Color256
Auto Trait Implementations§
impl Freeze for Color256
impl RefUnwindSafe for Color256
impl Send for Color256
impl Sync for Color256
impl Unpin for Color256
impl UnwindSafe for Color256
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()
Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more