pub enum Color {
}Expand description
ANSI Color
All colors from the ANSI color table are supported (though some names are not exactly the same).
| Color Name | Color | Foreground | Background |
|---|---|---|---|
black | Color::Black | 30 | 40 |
red | Color::Red | 31 | 41 |
green | Color::Green | 32 | 42 |
yellow | Color::Yellow | 33 | 43 |
blue | Color::Blue | 34 | 44 |
magenta | Color::Magenta | 35 | 45 |
cyan | Color::Cyan | 36 | 46 |
gray* | Color::Gray | 37 | 47 |
darkgray* | Color::DarkGray | 90 | 100 |
lightred | Color::LightRed | 91 | 101 |
lightgreen | Color::LightGreen | 92 | 102 |
lightyellow | Color::LightYellow | 93 | 103 |
lightblue | Color::LightBlue | 94 | 104 |
lightmagenta | Color::LightMagenta | 95 | 105 |
lightcyan | Color::LightCyan | 96 | 106 |
white* | Color::White | 97 | 107 |
grayis sometimes calledwhite- this is not supported as we usewhitefor bright whitegrayis sometimes calledsilver- this is supporteddarkgrayis sometimes calledlight blackorbright black(both are supported)whiteis sometimes calledlight whiteorbright white(both are supported)- we support
brightandlightprefixes for all colors - we support
-and_andas separators for all colors - we support both
grayandgreyspellings
From<Color> for Style is implemented by creating a style with the foreground color set to the
given color. This allows you to use colors anywhere that accepts Into<Style>.
§Example
use std::str::FromStr;
use ratatui::style::Color;
assert_eq!(Color::from_str("red"), Ok(Color::Red));
assert_eq!("red".parse(), Ok(Color::Red));
assert_eq!("lightred".parse(), Ok(Color::LightRed));
assert_eq!("light red".parse(), Ok(Color::LightRed));
assert_eq!("light-red".parse(), Ok(Color::LightRed));
assert_eq!("light_red".parse(), Ok(Color::LightRed));
assert_eq!("lightRed".parse(), Ok(Color::LightRed));
assert_eq!("bright red".parse(), Ok(Color::LightRed));
assert_eq!("bright-red".parse(), Ok(Color::LightRed));
assert_eq!("silver".parse(), Ok(Color::Gray));
assert_eq!("dark-grey".parse(), Ok(Color::DarkGray));
assert_eq!("dark gray".parse(), Ok(Color::DarkGray));
assert_eq!("light-black".parse(), Ok(Color::DarkGray));
assert_eq!("white".parse(), Ok(Color::White));
assert_eq!("bright white".parse(), Ok(Color::White));Variants§
Reset
Resets the foreground or background color
Black
ANSI Color: Black. Foreground: 30, Background: 40
Red
ANSI Color: Red. Foreground: 31, Background: 41
Green
ANSI Color: Green. Foreground: 32, Background: 42
Yellow
ANSI Color: Yellow. Foreground: 33, Background: 43
Blue
ANSI Color: Blue. Foreground: 34, Background: 44
Magenta
ANSI Color: Magenta. Foreground: 35, Background: 45
Cyan
ANSI Color: Cyan. Foreground: 36, Background: 46
Gray
ANSI Color: White. Foreground: 37, Background: 47
Note that this is sometimes called silver or white but we use white for bright white
DarkGray
ANSI Color: Bright Black. Foreground: 90, Background: 100
Note that this is sometimes called light black or bright black but we use dark gray
LightRed
ANSI Color: Bright Red. Foreground: 91, Background: 101
LightGreen
ANSI Color: Bright Green. Foreground: 92, Background: 102
LightYellow
ANSI Color: Bright Yellow. Foreground: 93, Background: 103
LightBlue
ANSI Color: Bright Blue. Foreground: 94, Background: 104
LightMagenta
ANSI Color: Bright Magenta. Foreground: 95, Background: 105
LightCyan
ANSI Color: Bright Cyan. Foreground: 96, Background: 106
White
ANSI Color: Bright White. Foreground: 97, Background: 107
Sometimes called bright white or light white in some terminals
Rgb(u8, u8, u8)
An RGB color.
Note that only terminals that support 24-bit true color will display this correctly. Notably versions of Windows Terminal prior to Windows 10 and macOS Terminal.app do not support this.
If the terminal does not support true color, code using the TermwizBackend will
fallback to the default text color. Crossterm and Termion do not have this capability and
the display will be unpredictable (e.g. Terminal.app may display glitched blinking text).
See https://github.com/ratatui/ratatui/issues/475 for an example of this problem.
See also: https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit
Indexed(u8)
An 8-bit 256 color.
See also https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
Implementations§
Trait Implementations§
Source§impl FromStr for Color
Converts a string representation to a Color instance.
impl FromStr for Color
Converts a string representation to a Color instance.
The from_str function attempts to parse the given string and convert it to the corresponding
Color variant. It supports named colors, RGB values, and indexed colors. If the string cannot
be parsed, a ParseColorError is returned.
See the Color documentation for more information on the supported color names.
§Examples
use std::str::FromStr;
use ratatui::style::Color;
let color: Color = Color::from_str("blue").unwrap();
assert_eq!(color, Color::Blue);
let color: Color = Color::from_str("#FF0000").unwrap();
assert_eq!(color, Color::Rgb(255, 0, 0));
let color: Color = Color::from_str("10").unwrap();
assert_eq!(color, Color::Indexed(10));
let color: Result<Color, _> = Color::from_str("invalid_color");
assert!(color.is_err());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 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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more