Struct that contains both the style and the content wits can be styled.
Set the foreground of the styled object to the passed Color
.
use self::crossterm::style::{style,Color};
let styledobject = style("Some colored text").with(Color::Red);
let styledobject1 = style("Some colored text").with(Color::Blue);
println!("{}", styledobject);
println!("{}", styledobject1);
println!("{}", style("Some colored text").on(Color::Blue));
Set the background of the styled object to the passed Color
.
#Example
use self::crossterm::style::{style,Color};
let styledobject = style("Some colored text").on(Color::Red);
let styledobject1 = style("Some colored text").on(Color::Blue);
println!("{}", styledobject);
println!("{}", styledobject1);
println!("{}", style("Some colored text").on(Color::Blue));
Set the attribute of an styled object to the passed Attribute
.
#Example
extern crate crossterm;
use self::crossterm::style::{style,Attribute};
println!("{}", style("Some bold text").attr(Attribute::Bold);
Increase the font intensity.
Faint (decreased intensity) (Not widely supported).
Make the font italic (Not widely supported; Sometimes treated as inverse).
Slow Blink (less than 150 per minute; not widely supported).
Rapid Blink (MS-DOS ANSI.SYS; 150+ per minute; not widely supported).
Swap foreground and background colors.
Hide text (Not widely supported).
Characters legible, but marked for deletion. Not widely supported.
This could be used to paint the styled object onto the given screen. You have to pass a reference to the screen whereon you want to perform the painting.
style("Some colored text")
.with(Color::Blue)
.on(Color::Black)
.paint(&screen);
You should take not that StyledObject
implements Display
. You don't need to call paint unless you are on alternate screen.
Checkout into_displayable()
for more information about this.
This converts an styled object into an DisplayableObject
witch implements: Display
and could be used inside the write function of the standard library.
StyledObject already implements Display
right?
This is true, however there are some complex issues why this won't work on alternate screen.
That is the reason why this functions exists.
You could just pass in the 'screen' from your alternate screen to this method and your StyledObject
will be printed to the alternate screen just fine.
let screen = Screen::default();
let styled_object = style("test").with(Color::Yellow);
let display_object = styled_object.into_displayable(&screen);
println!("Colored text: {}. Default color", display_object);
Formats the value using the given formatter. Read more
Converts the given value to a String
. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static