StyleBuilder

Struct StyleBuilder 

Source
pub struct StyleBuilder { /* private fields */ }
Expand description

A helper struct for creating the Style object

Implementations§

Source§

impl StyleBuilder

Source

pub fn new() -> Self

Creates a new StyleBuilder struct for creating styles

Source

pub fn bold(self) -> Self

Sets the bold property to true

Source

pub fn dim(self) -> Self

Sets the dim property to true

Source

pub fn italic(self) -> Self

Sets the italic property to true

Source

pub fn underline(self) -> Self

Sets the underline property to true

Sets the blink property to true

Source

pub fn inverse(self) -> Self

Sets the inverse property to true

Source

pub fn hidden(self) -> Self

Sets the hidden property to true

Source

pub fn strikethrough(self) -> Self

Sets the strikethrough property to true

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}
Source

pub fn overline(self) -> Self

Sets the overline property to true

Source

pub fn black(self) -> Self

Sets the text color to black

Source

pub fn red(self) -> Self

Sets the text color to red

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}
Source

pub fn green(self) -> Self

Sets the text color to green

Source

pub fn yellow(self) -> Self

Sets the text color to yellow

Source

pub fn blue(self) -> Self

Sets the text color to blue

Source

pub fn magenta(self) -> Self

Sets the text color to magenta

Source

pub fn cyan(self) -> Self

Sets the text color to cyan

Source

pub fn white(self) -> Self

Sets the text color to white

Source

pub fn black_bright(self) -> Self

Sets the text color to a bright black (gray)

Source

pub fn red_bright(self) -> Self

Sets the text color to a bright red

Source

pub fn green_bright(self) -> Self

Sets the text color to a bright green

Source

pub fn yellow_bright(self) -> Self

Sets the text color to a bright yellow

Source

pub fn blue_bright(self) -> Self

Sets the text color to a bright blue

Source

pub fn magenta_bright(self) -> Self

Sets the text color to a bright magenta

Source

pub fn cyan_bright(self) -> Self

Sets the text color to a bright cyan

Source

pub fn white_bright(self) -> Self

Sets the text color to a bright white

Source

pub fn bg_black(self) -> Self

Sets the text’s bckground color to black

Source

pub fn bg_red(self) -> Self

Sets the text’s bckground color to red

Source

pub fn bg_green(self) -> Self

Sets the text’s bckground color to green

Source

pub fn bg_yellow(self) -> Self

Sets the text’s bckground color to yellow

Source

pub fn bg_blue(self) -> Self

Sets the text’s bckground color to blue

Source

pub fn bg_magenta(self) -> Self

Sets the text’s bckground color to magenta

Source

pub fn bg_cyan(self) -> Self

Sets the text’s bckground color to cyan

Source

pub fn bg_white(self) -> Self

Sets the text’s bckground color to white

Source

pub fn bg_black_bright(self) -> Self

Sets the text’s bckground color to a bright black (gray)

Source

pub fn bg_red_bright(self) -> Self

Sets the text’s bckground color to a bright red

Source

pub fn bg_green_bright(self) -> Self

Sets the text’s bckground color to a bright green

Source

pub fn bg_yellow_bright(self) -> Self

Sets the text’s bckground color to a bright yellow

Source

pub fn bg_blue_bright(self) -> Self

Sets the text’s bckground color to a bright blue

Source

pub fn bg_magenta_bright(self) -> Self

Sets the text’s bckground color to a bright magenta

Source

pub fn bg_cyan_bright(self) -> Self

Sets the text’s bckground color to a bright cyan

Source

pub fn bg_white_bright(self) -> Self

Sets the text’s bckground color to a bright white

Source

pub fn build(self) -> Style

Builds a Style struct from a the current instance of the 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}

Trait Implementations§

Source§

impl Default for StyleBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, 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.