pub struct Style { /* private fields */ }Expand description
A collection of properties that can be used to format a string using ANSI escape codes.
Implementations§
Source§impl Style
impl Style
Sourcepub fn builder() -> StyleBuilder
pub fn builder() -> StyleBuilder
Creates a new StyleBuilder struct
Examples found in repository?
examples/console.rs (line 16)
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}Checks whether or not the text’s style is hidden
Sourcepub fn strikethrough(&self) -> bool
pub fn strikethrough(&self) -> bool
Checks whether or not the text’s style is strikethrough
Sourcepub fn color(&self) -> Color
pub fn color(&self) -> Color
Checks whether oor not the current style has a text color if no color is
provided a default color Color::Any will be provided
Sourcepub fn bg_color(&self) -> BGColor
pub fn bg_color(&self) -> BGColor
Checks whether oor not the current style has a text background color if no color is
provided a default color BGColor::Any will be provided
Sourcepub fn rgb_to_ansi256(red: u8, green: u8, blue: u8) -> u8
pub fn rgb_to_ansi256(red: u8, green: u8, blue: u8) -> u8
Converts three values (red, green, blue) to an ansi 256-color lookup (8-bit)
§Arguments
red- a number representation for redgreen- a number representation for greenblue- a number representation for blue
Sourcepub fn stylize(&self, text: &str) -> String
pub fn stylize(&self, text: &str) -> String
Adds style to a given text
text- the string of characters to add style to
Examples found in repository?
examples/console.rs (line 18)
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 Style
impl Ord for Style
Source§impl PartialOrd for Style
impl PartialOrd for Style
impl Copy for Style
impl Eq for Style
impl StructuralPartialEq for Style
Auto Trait Implementations§
impl Freeze for Style
impl RefUnwindSafe for Style
impl Send for Style
impl Sync for Style
impl Unpin for Style
impl UnwindSafe for Style
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