Struct crossterm::style::color::TerminalColor
source · pub struct TerminalColor<'stdout> { /* private fields */ }
Expand description
Struct that stores an specific platform 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§
source§impl<'stdout> TerminalColor<'stdout>
impl<'stdout> TerminalColor<'stdout>
sourcepub fn new() -> TerminalColor<'stdout>
pub fn new() -> TerminalColor<'stdout>
Create new instance whereon color related actions can be performed.
sourcepub fn on_screen(stdout: &'stdout Arc<TerminalOutput>) -> TerminalColor<'stdout>
pub fn on_screen(stdout: &'stdout Arc<TerminalOutput>) -> TerminalColor<'stdout>
Create new instance of TerminalInput
whereon input related actions could be preformed.
sourcepub fn set_fg(&self, color: Color)
pub fn set_fg(&self, color: Color)
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"));
sourcepub fn set_bg(&self, color: Color)
pub fn set_bg(&self, color: Color)
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"));
sourcepub fn reset(&self)
pub fn reset(&self)
Reset the terminal colors and attributes to default.
let colored_terminal = color();
colored_terminal.reset();
sourcepub fn get_available_color_count(&self) -> Result<u16>
pub fn get_available_color_count(&self) -> Result<u16>
Get available color count.