pub struct Crossterm { /* private fields */ }
Expand description
This type could be used to access the cursor, terminal, color, input, styling
module more easily.
You need to pass a reference to the screen where on you want to perform the actions to the Crossterm
type.
If you want to use the default screen you could do it like this:
extern crate crossterm;
use crossterm::{Crossterm, Screen};
let crossterm = Crossterm::new(&Screen::default());
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
.
extern crate crossterm;
use crossterm::{Crossterm, 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();
}
Implementations§
source§impl<'crossterm> Crossterm
impl<'crossterm> Crossterm
sourcepub fn from_screen(screen: &Screen) -> Crossterm
pub fn from_screen(screen: &Screen) -> Crossterm
Create a new instance of Crossterm
sourcepub fn cursor(&self) -> TerminalCursor<'_>
pub fn cursor(&self) -> TerminalCursor<'_>
Get an TerminalCursor
implementation whereon cursor related actions can be performed.
extern crate crossterm;
use crossterm::Crossterm;
let crossterm = Crossterm::new();
let cursor = crossterm.cursor();
sourcepub fn input(&self) -> TerminalInput<'_>
pub fn input(&self) -> TerminalInput<'_>
Get an TerminalInput
implementation whereon terminal related actions can be performed.
extern crate crossterm;
use crossterm::Crossterm;
let crossterm = Crossterm::new();
let input = crossterm.input();
sourcepub fn terminal(&self) -> Terminal<'_>
pub fn terminal(&self) -> Terminal<'_>
Get an Terminal
implementation whereon terminal related actions can be performed.
extern crate crossterm;
use crossterm::Crossterm;
let crossterm = Crossterm::new();
let mut terminal = crossterm.terminal();
sourcepub fn color(&self) -> TerminalColor<'_>
pub fn color(&self) -> TerminalColor<'_>
Get an TerminalColor
implementation whereon color related actions can be performed.
extern crate crossterm;
use crossterm::Crossterm;
let crossterm = Crossterm::new();
let mut terminal = crossterm.color();
sourcepub fn style<D>(&self, val: D) -> StyledObject<D>where
D: Display,
pub fn style<D>(&self, val: D) -> StyledObject<D>where
D: Display,
This could be used to style an Displayable
type with colors and attributes.
extern crate crossterm;
use crossterm::Crossterm;
let crossterm = Crossterm::new();
// get an styled object which could be painted to the terminal.
let styled_object = crossterm.style("Some Blue colored text on black background")
.with(Color::Blue)
.on(Color::Black);
// print the styled font * times to the current screen.
for i in 1..10
{
println!("{}", styled_object);
}