[−][src]Module crossterm::style
A functionality to apply attributes and colors on your text.
Style
The style
module provides a functionality to apply attributes and colors on your text.
This documentation does not contain a lot of examples. The reason is that it's fairly obvious how to use this crate. Although, we do provide examples repository to demonstrate the capabilities.
Platform-specific Notes
Not all features are supported on all terminals/platforms. You should always consult platform-specific notes of the following types:
Examples
Colors
The command API:
use std::io::{stdout, Write}; use crossterm::{execute, Result, Output}; use crossterm::{SetBg, SetFg, ResetColor, Color, Attribute}; fn main() -> Result<()> { execute!( stdout(), // Blue foreground SetFg(Color::Blue), // Red background SetBg(Color::Red), Output("Styled text here.".to_string()), // Reset to default colors ResetColor ) }
use crossterm::{Colored, Color}; println!("{} Red foreground", Colored::Fg(Color::Red)); println!("{} Blue background", Colored::Bg(Color::Blue));
The Colorize
trait:
use crossterm::Colorize; println!("{}", "Red foreground color & blue background.".red().on_blue());
Attributes
The command API:
use std::io::{stdout, Write}; use crossterm::{execute, Result, Output}; use crossterm::{SetAttr, Attribute}; fn main() -> Result<()> { execute!( stdout(), // Set to bold SetAttr(Attribute::Bold), Output("Styled text here.".to_string()), // Reset all attributes SetAttr(Attribute::Reset) ) }
The Styler
trait:
use crossterm::Styler; println!("{}", "Bold".bold()); println!("{}", "Underlined".underlined()); println!("{}", "Negative".negative());
The Attribute
enum:
use crossterm::Attribute; println!( "{} Underlined {} No Underline", Attribute::Underlined, Attribute::NoUnderline );
Structs
ObjectStyle | An object style. |
PrintStyledFont | A command to print the styled object. |
ResetColor | A command to reset the colors back to default ones. |
SetAttr | A command to set the text attribute. |
SetBg | A command to set the background color. |
SetFg | A command to set the foreground color. |
StyledObject | A styled object. |
TerminalColor | A terminal color. |
Enums
Attribute | Represents an attribute. |
Color | Represents a color. |
Colored | Represents a foreground or a background color. |
Traits
Colorize | Provides a set of methods to set the colors. |
Styler | Provides a set of methods to set the text attributes. |
Functions
color | Creates a new |
style | Creates a |