pub struct TerminalColor<'stdout> { /* private fields */ }
Expand description

Struct that stores a platform-specific implementation for color related actions.

For styling text use the ::crossterm::style() function. TerminalColor will set the colors of the screen permanently and the style() will only style the text given.

Check /examples/color in the library for more specific examples.

use crossterm::style::color;

let colored_terminal = color();

// set foreground color
colored_terminal.set_fg(Color::Red);
// set background color
colored_terminal.set_bg(Color::Red);
// reset color to default
colored_terminal.reset();

When you want to use ‘color’ on ‘alternate screen’ use the Screen type instead and pass it to the color::from_screen() function. By doing that styling actions will be performed on the alternate screen.

Implementations§

Create new instance whereon color related actions can be performed.

Create a new instance of TerminalColor whereon coloring could be preformed on the given output.

Note

Use this function when you want your terminal to operate with a specific output. This could be useful when you have a screen which is in ‘alternate mode’. And you want your actions from the TerminalColor, created by this function, to operate on the ‘alternate screen’.

Example
let screen = Screen::default();
if let Ok(alternate) = screen.enable_alternate_modes(false) {
   let terminal = TerminalColor::from_output(&alternate.screen.stdout);
}

Set the foreground color to the given color.

let colored_terminal = color();

// Set foreground color of the font
colored_terminal.set_fg(Color::Red);
// crossterm provides to set the background from &str or String
colored_terminal.set_fg(Color::from("Red"));

Set the background color to the given color.

let colored_terminal = color();

// Set background color of the font
colored_terminal.set_bg(Color::Red);
// crossterm provides to set the background from &str or String
colored_terminal.set_bg(Color::from("Red"));

Reset the terminal colors and attributes to default.

let colored_terminal = color();
colored_terminal.reset();

Get available color count.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.