pub struct Color {
pub name: String,
pub kind: ColorType,
pub number: Option<u8>,
pub triplet: Option<ColorTriplet>,
}Expand description
A parsed color. Mirrors rich.color.Color.
Fields§
§name: StringThe original name/spec the color was created from.
kind: ColorType§number: Option<u8>Palette index for Standard/EightBit/Windows.
triplet: Option<ColorTriplet>Explicit RGB for Truecolor.
Implementations§
Source§impl Color
impl Color
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Whether this is the terminal default color. Port of Color.is_default.
Sourcepub fn default_color() -> Self
pub fn default_color() -> Self
The terminal default color.
Sourcepub fn from_ansi(number: u8) -> Self
pub fn from_ansi(number: u8) -> Self
A color from an 8-bit ANSI number (0–15 standard, 16–255 palette).
Port of Color.from_ansi.
Sourcepub fn from_rgb(red: u8, green: u8, blue: u8) -> Self
pub fn from_rgb(red: u8, green: u8, blue: u8) -> Self
A truecolor from explicit RGB channels. Port of Color.from_rgb
(via from_triplet): the name is the #rrggbb hex.
Sourcepub fn parse(color: &str) -> Result<Self>
pub fn parse(color: &str) -> Result<Self>
Parse a color from a string spec.
Accepts: a standard color name, default, #rrggbb, rgb(r,g,b), and
color(N). Mirrors the common paths of Color.parse.
Sourcepub fn get_truecolor(&self) -> Option<ColorTriplet>
pub fn get_truecolor(&self) -> Option<ColorTriplet>
Resolve this color to an RGB triplet, using the palettes for indexed colors.
Returns None only for ColorType::Default.
Sourcepub fn ansi_codes(&self, foreground: bool) -> Vec<String>
pub fn ansi_codes(&self, foreground: bool) -> Vec<String>
The SGR parameter list for this color (without the leading \x1b[).
Port of Color.get_ansi_codes.
Sourcepub fn downgrade(&self, system: ColorSystem) -> Color
pub fn downgrade(&self, system: ColorSystem) -> Color
Return a version of this color representable in system.
Port of the reducing half of Color.downgrade: colors are only ever
converted down to a smaller system, never up.
Trait Implementations§
impl Eq for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<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.