Struct Color256

Source
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

Source

pub const BLACK: Color256

Color 0

Source

pub const RED: Color256

Color 1, also known as “dark red”

Source

pub const GREEN: Color256

Color 2, also known as “dark green”

Source

pub const YELLOW: Color256

Color 3, also known as “dark yellow”

Source

pub const BLUE: Color256

Color 4, also known as “dark blue”

Source

pub const MAGENTA: Color256

Color 5, also known as “dark magenta”

Source

pub const CYAN: Color256

Color 6, also known as “dark cyan”

Source

pub const WHITE: Color256

Color 7, also known as “grey”

Source

pub const BRIGHT_BLACK: Color256

Color 8, also known as “dark grey” or “grey”

Source

pub const BRIGHT_RED: Color256

Color 9

Source

pub const BRIGHT_GREEN: Color256

Color 10

Source

pub const BRIGHT_YELLOW: Color256

Color 11

Source

pub const BRIGHT_BLUE: Color256

Color 12

Source

pub const BRIGHT_MAGENTA: Color256

Color 13

Source

pub const BRIGHT_CYAN: Color256

Color 14

Source

pub const BRIGHT_WHITE: Color256

Color 15, also known as “white”

Source

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"));
Source

pub fn as_foreground(self) -> Style

Return a new Style that uses this color as the foreground color

Source

pub fn as_background(self) -> Style

Return a new Style that uses this color as the background color

Source

pub fn on<C: Into<Color>>(self, bg: C) -> Style

Return a new Style that uses this color as the foreground color and bg as the background color

Trait Implementations§

Source§

impl Clone for Color256

Source§

fn clone(&self) -> Color256

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color256

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Color256

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Color256

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Ansi256Color> for Color256

Available on crate feature anstyle only.
Source§

fn from(value: Ansi256Color) -> Color256

Convert an anstyle::Ansi256Color to a Color256

Source§

impl From<AnsiColor> for Color256

Available on crate feature anstyle only.
Source§

fn from(value: AnsiColor) -> Color256

Convert an anstyle::AnsiColor to a Color256

Source§

impl From<Color256> for Ansi256Color

Available on crate feature anstyle only.
Source§

fn from(value: Color256) -> Ansi256Color

Convert a Color256 to an anstyle::Ansi256Color

Source§

impl From<Color256> for Color

Source§

fn from(value: Color256) -> Color

Converts to this type from the input type.
Source§

impl From<Color256> for Color

Available on crate feature crossterm only.
Source§

fn from(value: Color256) -> Color

Convert a Color256 to a crossterm::style::Color

Source§

impl From<Color256> for Color

Available on crate feature ratatui only.
Source§

fn from(value: Color256) -> Color

Convert a Color256 to a ratatui::style::Color

Source§

impl From<Color256> for u8

Source§

fn from(value: Color256) -> u8

Converts to this type from the input type.
Source§

impl From<u8> for Color256

Source§

fn from(value: u8) -> Color256

Converts to this type from the input type.
Source§

impl FromStr for Color256

Source§

type Err = ParseColorError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Color256, ParseColorError>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Color256

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Color256

Source§

fn cmp(&self, other: &Color256) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Color256

Source§

fn eq(&self, other: &Color256) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Color256

Source§

fn partial_cmp(&self, other: &Color256) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Color256

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Color256

Source§

impl Eq for Color256

Source§

impl StructuralPartialEq for Color256

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,