pub struct Color {
pub name: CompactString,
pub kind: ColorType,
pub number: Option<u8>,
pub triplet: Option<ColorTriplet>,
}Expand description
A parsed color. Mirrors rich.color.Color.
Fields§
§name: CompactStringThe original name/spec the color was created from: a
CompactString, kept inline up to 24 bytes,
so a colour’s name (#rrggbb, bright_red) allocates nothing.
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. Port of Color.parse.
Accepts a color name from ANSI_COLOR_NAMES, default, #rrggbb,
color(N) (one to three digits) and rgb(r,g,b), case-insensitively
and ignoring surrounding whitespace. The errors carry upstream’s
ColorParseError messages.
Sourcepub fn from_triplet(triplet: ColorTriplet) -> Self
pub fn from_triplet(triplet: ColorTriplet) -> Self
A truecolor from a triplet; the name is its #rrggbb hex. Port of
Color.from_triplet.
Sourcepub fn system(&self) -> ColorSystem
pub fn system(&self) -> ColorSystem
The native color system of this color: standard for the default
color. Port of the Color.system property.
Sourcepub fn is_system_defined(&self) -> bool
pub fn is_system_defined(&self) -> bool
Whether the terminal defines the actual color: true for the default,
standard and Windows colors. Port of Color.is_system_defined.
Sourcepub fn get_truecolor_for(
&self,
theme: Option<&TerminalTheme>,
foreground: bool,
) -> ColorTriplet
pub fn get_truecolor_for( &self, theme: Option<&TerminalTheme>, foreground: bool, ) -> ColorTriplet
The RGB triplet this color shows as under theme (the default export
theme when None). A standard color takes the theme’s ANSI color and
the default color the theme’s foreground or background. Port of
Color.get_truecolor(theme, foreground).
Sourcepub fn rich_text(&self) -> Text
pub fn rich_text(&self) -> Text
The text upstream prints for a color: <color 'red' (standard)⬤ >,
the dot in the color itself. Port of Color.__rich__.
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 Color.downgrade: colors are only ever converted down to a
smaller system, never up, and a Windows console matches against the
Windows 10 console palette (WINDOWS_PALETTE), not the standard one.
Trait Implementations§
impl Eq for Color
Source§impl Renderable for Color
A color prints as its description and a dot in the color. Port of
Color.__rich__.
impl Renderable for Color
A color prints as its description and a dot in the color. Port of
Color.__rich__.
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
(minimum, maximum) cell width this renderable wants. Port of
__rich_measure__. The default is what upstream’s Measurement.get
returns for a renderable without one: anything from nothing to the
whole width, (0, max_width).Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.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.