Color

Enum Color 

Source
pub enum Color {
Show 19 variants Default, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, BrightBlack, BrightRed, BrightGreen, BrightYellow, BrightBlue, BrightMagenta, BrightCyan, BrightWhite, Ansi256(u8), Rgb { r: u8, g: u8, b: u8, },
}
Expand description

A terminal color.

Variantsยง

ยง

Default

Default terminal color.

ยง

Black

Black (ANSI 0).

ยง

Red

Red (ANSI 1).

ยง

Green

Green (ANSI 2).

ยง

Yellow

Yellow (ANSI 3).

ยง

Blue

Blue (ANSI 4).

ยง

Magenta

Magenta (ANSI 5).

ยง

Cyan

Cyan (ANSI 6).

ยง

White

White (ANSI 7).

ยง

BrightBlack

Bright black (ANSI 8).

ยง

BrightRed

Bright red (ANSI 9).

ยง

BrightGreen

Bright green (ANSI 10).

ยง

BrightYellow

Bright yellow (ANSI 11).

ยง

BrightBlue

Bright blue (ANSI 12).

ยง

BrightMagenta

Bright magenta (ANSI 13).

ยง

BrightCyan

Bright cyan (ANSI 14).

ยง

BrightWhite

Bright white (ANSI 15).

ยง

Ansi256(u8)

256-color palette (0-255).

ยง

Rgb

True color RGB.

Fields

ยงr: u8

Red component (0-255).

ยงg: u8

Green component (0-255).

ยงb: u8

Blue component (0-255).

Implementationsยง

Sourceยง

impl Color

Source

pub const fn rgb(r: u8, g: u8, b: u8) -> Color

Create an RGB color.

Source

pub fn from_hex(hex: &str) -> Color

Create a color from a hex string (with or without #).

ยงPanics

Panics if the hex string is invalid.

Source

pub const fn ansi256(code: u8) -> Color

Create a 256-color palette color.

Source

pub fn fg_code(&self) -> String

Get the ANSI SGR code for foreground.

Source

pub fn bg_code(&self) -> String

Get the ANSI SGR code for background.

Source

pub fn name(&self) -> String

Get a human-readable name for the color.

Trait Implementationsยง

Sourceยง

impl Clone for Color

Sourceยง

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0ยง

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

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for Color

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl Display for Color

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl Hash for Color

Sourceยง

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

Feeds this value into the given Hasher. Read more
1.3.0ยง

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 PartialEq for Color

Sourceยง

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

Tests for self and other values to be equal, and is used by ==.
1.0.0ยง

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 Copy for Color

Sourceยง

impl Eq for Color

Sourceยง

impl StructuralPartialEq for Color

Auto Trait Implementationsยง

Blanket Implementationsยง

ยง

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

ยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
ยง

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

ยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
ยง

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

ยง

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

Mutably borrows from an owned value. Read more
ยง

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

ยง

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
ยง

impl<T> From<T> for T

ยง

fn from(t: T) -> T

Returns the argument unchanged.

ยง

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

ยง

fn into(self) -> U

Calls U::from(self).

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

ยง

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

ยง

type Owned = T

The resulting type after obtaining ownership.
ยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
ยง

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

Uses borrowed data to replace owned data, usually by cloning. Read more
ยง

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

ยง

fn to_string(&self) -> String

Converts the given value to a String. Read more
ยง

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

ยง

type Error = Infallible

The type returned in the event of a conversion error.
ยง

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

Performs the conversion.
ยง

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

ยง

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

The type returned in the event of a conversion error.
ยง

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

Performs the conversion.