[−][src]Crate crossterm_style
Style
The crossterm_style
crate is deprecated and no longer maintained. The GitHub repository will
be archived soon. All the code is being moved to the crossterm
crate. You can learn more in
the Merge sub-crates to the crossterm crate
issue.
The crossterm_style
crate 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_utils::{execute, Result, Output}; use crossterm_style::{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_style::{Colored, Color}; println!("{} Red foreground", Colored::Fg(Color::Red)); println!("{} Blue background", Colored::Bg(Color::Blue));
The Colorize
trait:
use crossterm_style::Colorize; println!("{}", "Red foreground color & blue background.".red().on_blue());
Attributes
The command API:
use std::io::{stdout, Write}; use crossterm_utils::{execute, Result, Output}; use crossterm_style::{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_style::Styler; println!("{}", "Bold".bold()); println!("{}", "Underlined".underlined()); println!("{}", "Negative".negative());
The Attribute
enum:
use crossterm_style::Attribute; println!( "{} Underlined {} No Underline", Attribute::Underlined, Attribute::NoUnderline );
Re-exports
pub use crossterm_utils::execute; |
pub use crossterm_utils::impl_display; |
pub use crossterm_utils::queue; |
pub use crossterm_utils::Command; |
pub use crossterm_utils::ExecutableCommand; |
pub use crossterm_utils::QueueableCommand; |
pub use crossterm_utils::Result; |
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 |