pub struct Color { /* private fields */ }Expand description
Full set of named ANSI colors. Use Color::name_to_index() to look up.
A terminal color.
Can be one of: default (inherit), a standard ANSI name, an 8-bit palette index, or a 24-bit true-color RGB triple.
Implementations§
Source§impl Color
impl Color
Sourcepub fn from_ansi_name(name: &str) -> Option<Self>
pub fn from_ansi_name(name: &str) -> Option<Self>
Create from an ANSI standard name (e.g. “red”, “bright_blue”).
Sourcepub fn from_hex(hex: &str) -> Result<Self, ColorParseError>
pub fn from_hex(hex: &str) -> Result<Self, ColorParseError>
Create from a hex string like “#ff0000” or “ff0000”.
Sourcepub fn parse(s: &str) -> Result<Self, ColorParseError>
pub fn parse(s: &str) -> Result<Self, ColorParseError>
Parse a color from a string (name, hex, or “default”).
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Is this the default/inherit color?
Sourcepub fn from_triplet(triplet: &ColorTriplet) -> Self
pub fn from_triplet(triplet: &ColorTriplet) -> Self
Create a Color from a ColorTriplet.
§Examples
use rusty_rich::color::{Color, ColorTriplet};
let triplet = ColorTriplet::new(255, 0, 0);
let color = Color::from_triplet(&triplet);
assert!(!color.is_default());Sourcepub fn is_system_defined(&self) -> bool
pub fn is_system_defined(&self) -> bool
Returns true if this is a system-defined (non-custom) color.
System-defined colors are standard ANSI colors or named 8-bit palette entries. TrueColor and Default colors are not system-defined.
Sourcepub fn get_ansi_codes(
&self,
background: bool,
) -> (Option<String>, Option<String>)
pub fn get_ansi_codes( &self, background: bool, ) -> (Option<String>, Option<String>)
Get the ANSI escape codes for this color as a foreground/background pair.
Returns (foreground_code, background_code) as decimal strings suitable
for use in SGR sequences like \x1b[38;5;<code>m.
§Examples
use rusty_rich::Color;
let red = Color::parse("red").unwrap();
let (fg, bg) = red.get_ansi_codes(false);
assert_eq!(fg, Some("31".to_string()));Sourcepub fn name(&self) -> Option<&'static str>
pub fn name(&self) -> Option<&'static str>
Get the name of this color, if it has one.
For Standard and EightBit colors that were created from a name, this
returns the original name. For TrueColor and Default colors, returns
None.
Sourcepub fn number(&self) -> Option<u8>
pub fn number(&self) -> Option<u8>
Get the ANSI palette number for this color, if applicable.
Returns Some(n) for Standard (0–15) and EightBit (0–255) colors.
Returns None for TrueColor and Default colors.
Sourcepub fn triplet(&self) -> Option<(u8, u8, u8)>
pub fn triplet(&self) -> Option<(u8, u8, u8)>
Get the RGB triplet for this color, if it has one.
Returns Some((r, g, b)) for TrueColor colors. For Standard and
EightBit colors, the palette is consulted to compute the equivalent
RGB values. Returns None for Default colors.
Sourcepub fn get_truecolor(&self, theme: &TerminalTheme) -> (u8, u8, u8)
pub fn get_truecolor(&self, theme: &TerminalTheme) -> (u8, u8, u8)
Get the RGB triplet if available (computes it for named/8-bit colors by looking up the palette).
Sourcepub fn downgrade(&self, system: ColorSystem) -> Self
pub fn downgrade(&self, system: ColorSystem) -> Self
Downgrade this color to the given color system.
Trait Implementations§
impl Copy for Color
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<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
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.Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more