pub struct Crossterm { /* fields omitted */ }
This type offers a easy way to use functionalities like cursor, terminal, color, input, styling
.
To get a cursor instance to perform cursor related actions, you can do the following:
let crossterm = Crossterm::new();
let cursor = crossterm.cursor();
If you want to perform actions on the AlternateScreen
make sure to pass a reference to the screen of the AlternateScreen
.
If you don't do this you actions won't be performed on the alternate screen but on the main screen.
let main_screen = Screen::default();
if let Ok(alternate_srceen) = main_screen.enable_alternate_modes(false)
{
let crossterm = Crossterm::new(&alternate_screen.screen);
let cursor = crossterm.cursor();
}
- depending on the feature flags you've enabled you are able to call methods of this type.
- checkout the crossterm book for more information about feature flags or alternate screen.
Create a new instance of Crossterm
Create a new instance of Crossterm
Get a TerminalCursor
implementation whereon cursor related actions can be performed.
let crossterm = Crossterm::new();
let cursor = crossterm.cursor();
Get a TerminalInput
implementation whereon terminal related actions can be performed.
let crossterm = Crossterm::new();
let input = crossterm.input();
Get a Terminal
implementation whereon terminal related actions can be performed.
let crossterm = Crossterm::new();
let mut terminal = crossterm.terminal();
Get a TerminalColor
implementation whereon color related actions can be performed.
let crossterm = Crossterm::new();
let mut terminal = crossterm.color();
This could be used to style any type implementing Display
with colors and attributes.
let crossterm = Crossterm::new();
let styled_object = crossterm.style("Some Blue colored text on black background")
.with(Color::Blue)
.on(Color::Black);
for i in 1..10
{
println!("{}", styled_object);
}
val
: any type implementing Display e.g. string.
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 note that StyledObject
implements Display
. You don't need to call paint unless you are on alternate screen.
Checkout StyledObject::into_displayable()
for more information about this.
🔬 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