pub trait Stylize: Sized {
    type Styled: AsRef<ContentStyle> + AsMut<ContentStyle>;

Show 64 methods // Required method fn stylize(self) -> Self::Styled; // Provided methods fn with(self, color: Color) -> Self::Styled { ... } fn on(self, color: Color) -> Self::Styled { ... } fn underline(self, color: Color) -> Self::Styled { ... } fn attribute(self, attr: Attribute) -> Self::Styled { ... } fn reset(self) -> Self::Styled { ... } fn bold(self) -> Self::Styled { ... } fn underlined(self) -> Self::Styled { ... } fn reverse(self) -> Self::Styled { ... } fn dim(self) -> Self::Styled { ... } fn italic(self) -> Self::Styled { ... } fn negative(self) -> Self::Styled { ... } fn slow_blink(self) -> Self::Styled { ... } fn rapid_blink(self) -> Self::Styled { ... } fn hidden(self) -> Self::Styled { ... } fn crossed_out(self) -> Self::Styled { ... } fn black(self) -> Self::Styled { ... } fn on_black(self) -> Self::Styled { ... } fn underline_black(self) -> Self::Styled { ... } fn dark_grey(self) -> Self::Styled { ... } fn on_dark_grey(self) -> Self::Styled { ... } fn underline_dark_grey(self) -> Self::Styled { ... } fn red(self) -> Self::Styled { ... } fn on_red(self) -> Self::Styled { ... } fn underline_red(self) -> Self::Styled { ... } fn dark_red(self) -> Self::Styled { ... } fn on_dark_red(self) -> Self::Styled { ... } fn underline_dark_red(self) -> Self::Styled { ... } fn green(self) -> Self::Styled { ... } fn on_green(self) -> Self::Styled { ... } fn underline_green(self) -> Self::Styled { ... } fn dark_green(self) -> Self::Styled { ... } fn on_dark_green(self) -> Self::Styled { ... } fn underline_dark_green(self) -> Self::Styled { ... } fn yellow(self) -> Self::Styled { ... } fn on_yellow(self) -> Self::Styled { ... } fn underline_yellow(self) -> Self::Styled { ... } fn dark_yellow(self) -> Self::Styled { ... } fn on_dark_yellow(self) -> Self::Styled { ... } fn underline_dark_yellow(self) -> Self::Styled { ... } fn blue(self) -> Self::Styled { ... } fn on_blue(self) -> Self::Styled { ... } fn underline_blue(self) -> Self::Styled { ... } fn dark_blue(self) -> Self::Styled { ... } fn on_dark_blue(self) -> Self::Styled { ... } fn underline_dark_blue(self) -> Self::Styled { ... } fn magenta(self) -> Self::Styled { ... } fn on_magenta(self) -> Self::Styled { ... } fn underline_magenta(self) -> Self::Styled { ... } fn dark_magenta(self) -> Self::Styled { ... } fn on_dark_magenta(self) -> Self::Styled { ... } fn underline_dark_magenta(self) -> Self::Styled { ... } fn cyan(self) -> Self::Styled { ... } fn on_cyan(self) -> Self::Styled { ... } fn underline_cyan(self) -> Self::Styled { ... } fn dark_cyan(self) -> Self::Styled { ... } fn on_dark_cyan(self) -> Self::Styled { ... } fn underline_dark_cyan(self) -> Self::Styled { ... } fn white(self) -> Self::Styled { ... } fn on_white(self) -> Self::Styled { ... } fn underline_white(self) -> Self::Styled { ... } fn grey(self) -> Self::Styled { ... } fn on_grey(self) -> Self::Styled { ... } fn underline_grey(self) -> Self::Styled { ... }
}
Expand description

Provides a set of methods to set attributes and colors.

§Examples

use crossterm::style::Stylize;

println!("{}", "Bold text".bold());
println!("{}", "Underlined text".underlined());
println!("{}", "Negative text".negative());
println!("{}", "Red on blue".red().on_blue());

Required Associated Types§

source

type Styled: AsRef<ContentStyle> + AsMut<ContentStyle>

This type with styles applied.

Required Methods§

source

fn stylize(self) -> Self::Styled

Styles this type.

Provided Methods§

source

fn with(self, color: Color) -> Self::Styled

Sets the foreground color.

source

fn on(self, color: Color) -> Self::Styled

Sets the background color.

source

fn underline(self, color: Color) -> Self::Styled

Sets the underline color.

source

fn attribute(self, attr: Attribute) -> Self::Styled

Styles the content with the attribute.

source

fn reset(self) -> Self::Styled

Applies the Reset attribute to the text.

source

fn bold(self) -> Self::Styled

Applies the Bold attribute to the text.

source

fn underlined(self) -> Self::Styled

Applies the Underlined attribute to the text.

source

fn reverse(self) -> Self::Styled

Applies the Reverse attribute to the text.

source

fn dim(self) -> Self::Styled

Applies the Dim attribute to the text.

source

fn italic(self) -> Self::Styled

Applies the Italic attribute to the text.

source

fn negative(self) -> Self::Styled

Applies the Reverse attribute to the text.

Applies the SlowBlink attribute to the text.

Applies the RapidBlink attribute to the text.

source

fn hidden(self) -> Self::Styled

Applies the Hidden attribute to the text.

source

fn crossed_out(self) -> Self::Styled

Applies the CrossedOut attribute to the text.

source

fn black(self) -> Self::Styled

Sets the foreground color to Black.

source

fn on_black(self) -> Self::Styled

Sets the background color to Black.

source

fn underline_black(self) -> Self::Styled

Sets the underline color to Black.

source

fn dark_grey(self) -> Self::Styled

Sets the foreground color to DarkGrey.

source

fn on_dark_grey(self) -> Self::Styled

Sets the background color to DarkGrey.

source

fn underline_dark_grey(self) -> Self::Styled

Sets the underline color to DarkGrey.

source

fn red(self) -> Self::Styled

Sets the foreground color to Red.

Examples found in repository?
examples/simple.rs (line 21)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> io::Result<()> {
    // Will init the window for you, handling all required procedures.
    let mut window = Window::init()?;

    // Ask the system to handle panics for us.
    handle_panics();

    loop {
        // Ask the window to draw, handle events, and fix sizing issues.
        // Duration is the time for which to poll events before re-rendering.
        window.update(Duration::from_millis(200))?;

        // Render elements to the window
        render!(
            window,
            vec2(0, 0) => [ "Hello World!" ],
            vec2(0, 1) => [ "Press `Enter` to exit!".red() ],
            vec2(0, 2) => [
                "Render ".red(),
                "Multiple ".yellow(),
                "Elements ",
                "In one go!".to_string()
            ],
        );

        // Check if the Enter Key was pressed, and exit the app if it was.
        if window.input().code(KeyCode::Enter) {
            break;
        }
    }

    // Restore the window, enabling the window to function normally again
    // If nothing will be run after this, once the window is dropped, this will be run implicitly.
    window.restore()
}
More examples
Hide additional examples
examples/inline.rs (line 30)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn progress_bar() -> io::Result<()> {
    let mut window = Window::init_inline(2)?;

    let timer = SystemTime::now();
    let duration = Duration::from_secs(3);

    // The Inline Render Loop
    loop {
        // Render's the Window and captures events
        window.update(Duration::ZERO)?;

        let amount_done = SystemTime::now().duration_since(timer).unwrap();

        let percent = amount_done.as_secs_f64() / duration.as_secs_f64();

        if percent >= 1.0 {
            break;
        }

        let x = (window.size().x as f64 * percent).round() as u16;

        // Create the progress bar text
        let text_green = "|".repeat(x as usize).green();
        let text_red = "|".repeat((window.size().x - x) as usize).red();

        // Render the Progress Bar
        render!(window,
            vec2(0, 1) => [ text_green ],
            vec2(x, 1) => [ text_red ],
            vec2(0, 0) => [ "Progress" ],
        );

        // End the loop if key is pressed early
        if window
            .input()
            .pressed(&KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL))
        {
            break;
        }
    }

    window.restore()
}
source

fn on_red(self) -> Self::Styled

Sets the background color to Red.

source

fn underline_red(self) -> Self::Styled

Sets the underline color to Red.

source

fn dark_red(self) -> Self::Styled

Sets the foreground color to DarkRed.

source

fn on_dark_red(self) -> Self::Styled

Sets the background color to DarkRed.

source

fn underline_dark_red(self) -> Self::Styled

Sets the underline color to DarkRed.

source

fn green(self) -> Self::Styled

Sets the foreground color to Green.

Examples found in repository?
examples/inline.rs (line 29)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn progress_bar() -> io::Result<()> {
    let mut window = Window::init_inline(2)?;

    let timer = SystemTime::now();
    let duration = Duration::from_secs(3);

    // The Inline Render Loop
    loop {
        // Render's the Window and captures events
        window.update(Duration::ZERO)?;

        let amount_done = SystemTime::now().duration_since(timer).unwrap();

        let percent = amount_done.as_secs_f64() / duration.as_secs_f64();

        if percent >= 1.0 {
            break;
        }

        let x = (window.size().x as f64 * percent).round() as u16;

        // Create the progress bar text
        let text_green = "|".repeat(x as usize).green();
        let text_red = "|".repeat((window.size().x - x) as usize).red();

        // Render the Progress Bar
        render!(window,
            vec2(0, 1) => [ text_green ],
            vec2(x, 1) => [ text_red ],
            vec2(0, 0) => [ "Progress" ],
        );

        // End the loop if key is pressed early
        if window
            .input()
            .pressed(&KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL))
        {
            break;
        }
    }

    window.restore()
}
source

fn on_green(self) -> Self::Styled

Sets the background color to Green.

source

fn underline_green(self) -> Self::Styled

Sets the underline color to Green.

source

fn dark_green(self) -> Self::Styled

Sets the foreground color to DarkGreen.

source

fn on_dark_green(self) -> Self::Styled

Sets the background color to DarkGreen.

source

fn underline_dark_green(self) -> Self::Styled

Sets the underline color to DarkGreen.

source

fn yellow(self) -> Self::Styled

Sets the foreground color to Yellow.

Examples found in repository?
examples/simple.rs (line 24)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> io::Result<()> {
    // Will init the window for you, handling all required procedures.
    let mut window = Window::init()?;

    // Ask the system to handle panics for us.
    handle_panics();

    loop {
        // Ask the window to draw, handle events, and fix sizing issues.
        // Duration is the time for which to poll events before re-rendering.
        window.update(Duration::from_millis(200))?;

        // Render elements to the window
        render!(
            window,
            vec2(0, 0) => [ "Hello World!" ],
            vec2(0, 1) => [ "Press `Enter` to exit!".red() ],
            vec2(0, 2) => [
                "Render ".red(),
                "Multiple ".yellow(),
                "Elements ",
                "In one go!".to_string()
            ],
        );

        // Check if the Enter Key was pressed, and exit the app if it was.
        if window.input().code(KeyCode::Enter) {
            break;
        }
    }

    // Restore the window, enabling the window to function normally again
    // If nothing will be run after this, once the window is dropped, this will be run implicitly.
    window.restore()
}
source

fn on_yellow(self) -> Self::Styled

Sets the background color to Yellow.

source

fn underline_yellow(self) -> Self::Styled

Sets the underline color to Yellow.

source

fn dark_yellow(self) -> Self::Styled

Sets the foreground color to DarkYellow.

source

fn on_dark_yellow(self) -> Self::Styled

Sets the background color to DarkYellow.

source

fn underline_dark_yellow(self) -> Self::Styled

Sets the underline color to DarkYellow.

source

fn blue(self) -> Self::Styled

Sets the foreground color to Blue.

source

fn on_blue(self) -> Self::Styled

Sets the background color to Blue.

source

fn underline_blue(self) -> Self::Styled

Sets the underline color to Blue.

source

fn dark_blue(self) -> Self::Styled

Sets the foreground color to DarkBlue.

source

fn on_dark_blue(self) -> Self::Styled

Sets the background color to DarkBlue.

source

fn underline_dark_blue(self) -> Self::Styled

Sets the underline color to DarkBlue.

source

fn magenta(self) -> Self::Styled

Sets the foreground color to Magenta.

source

fn on_magenta(self) -> Self::Styled

Sets the background color to Magenta.

source

fn underline_magenta(self) -> Self::Styled

Sets the underline color to Magenta.

source

fn dark_magenta(self) -> Self::Styled

Sets the foreground color to DarkMagenta.

source

fn on_dark_magenta(self) -> Self::Styled

Sets the background color to DarkMagenta.

source

fn underline_dark_magenta(self) -> Self::Styled

Sets the underline color to DarkMagenta.

source

fn cyan(self) -> Self::Styled

Sets the foreground color to Cyan.

source

fn on_cyan(self) -> Self::Styled

Sets the background color to Cyan.

source

fn underline_cyan(self) -> Self::Styled

Sets the underline color to Cyan.

source

fn dark_cyan(self) -> Self::Styled

Sets the foreground color to DarkCyan.

source

fn on_dark_cyan(self) -> Self::Styled

Sets the background color to DarkCyan.

source

fn underline_dark_cyan(self) -> Self::Styled

Sets the underline color to DarkCyan.

source

fn white(self) -> Self::Styled

Sets the foreground color to White.

source

fn on_white(self) -> Self::Styled

Sets the background color to White.

source

fn underline_white(self) -> Self::Styled

Sets the underline color to White.

source

fn grey(self) -> Self::Styled

Sets the foreground color to Grey.

source

fn on_grey(self) -> Self::Styled

Sets the background color to Grey.

source

fn underline_grey(self) -> Self::Styled

Sets the underline color to Grey.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Stylize for &str

source§

impl Stylize for char

source§

impl Stylize for String

Implementors§