pub enum Color {
}Expand description
Variants§
Any
A generic color
Black
A black text color
Red
A red text color
Green
A green text color
Yellow
A yellow text color
Blue
A blue text color
Magenta
A magenta text color
Cyan
A cyan text color
White
A white text color
BlackBright
A bright black (gray) text color
RedBright
A bright red text color
GreenBright
A bright green text color
YellowBright
A bright yellow text color
BlueBright
A bright blue text color
MagentaBright
A bright magenta text color
CyanBright
A bright cyan text color
WhiteBright
A bright white text color
Ansi256(u8)
An 8-bit color from 0 to 255
RGB(u8, u8, u8)
A 24-bit RGB color, as specified by ISO-8613-3.
Implementations§
Source§impl Color
impl Color
Sourcepub fn close(&self) -> &'static str
pub fn close(&self) -> &'static str
Closes the terminal from adding selected color to text
Examples found in repository?
examples/console.rs (line 8)
3fn main() {
4 // You can either color the text directly with the Color enumeration
5 println!(
6 "{}Cyan colored \"Hello World!\"{}",
7 Color::Cyan.open(),
8 Color::Cyan.close()
9 );
10
11 // or you can use the builder function from within the Style stuct
12 // to create a style that can be used for more than one instance of
13 // a string and you wouldn't need to have an open and close function
14 // prepended and appended to every text you type like the above example
15
16 let style = Style::builder().red().strikethrough().build();
17
18 println!("{}", style.stylize("Hello World in red with strikethrough"));
19
20 println!("This is in red: {}", Color::Red.paint("a red string"));
21}Sourcepub fn open(&self) -> String
pub fn open(&self) -> String
Opens the terminal for adding selected color to text
Examples found in repository?
examples/console.rs (line 7)
3fn main() {
4 // You can either color the text directly with the Color enumeration
5 println!(
6 "{}Cyan colored \"Hello World!\"{}",
7 Color::Cyan.open(),
8 Color::Cyan.close()
9 );
10
11 // or you can use the builder function from within the Style stuct
12 // to create a style that can be used for more than one instance of
13 // a string and you wouldn't need to have an open and close function
14 // prepended and appended to every text you type like the above example
15
16 let style = Style::builder().red().strikethrough().build();
17
18 println!("{}", style.stylize("Hello World in red with strikethrough"));
19
20 println!("This is in red: {}", Color::Red.paint("a red string"));
21}Sourcepub fn paint(&self, text: &str) -> String
pub fn paint(&self, text: &str) -> String
Adds color to a given text
text- the string of characters to add background color to
Examples found in repository?
examples/console.rs (line 20)
3fn main() {
4 // You can either color the text directly with the Color enumeration
5 println!(
6 "{}Cyan colored \"Hello World!\"{}",
7 Color::Cyan.open(),
8 Color::Cyan.close()
9 );
10
11 // or you can use the builder function from within the Style stuct
12 // to create a style that can be used for more than one instance of
13 // a string and you wouldn't need to have an open and close function
14 // prepended and appended to every text you type like the above example
15
16 let style = Style::builder().red().strikethrough().build();
17
18 println!("{}", style.stylize("Hello World in red with strikethrough"));
19
20 println!("This is in red: {}", Color::Red.paint("a red string"));
21}Trait Implementations§
Source§impl Ord for Color
impl Ord for Color
Source§impl PartialOrd for Color
impl PartialOrd for Color
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
Mutably borrows from an owned value. Read more