Struct crossterm::Crossterm

source ·
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§

Create a new instance of Crossterm

Create a new instance of Crossterm

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();

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();

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();

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();

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);
}

Trait Implementations§

Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.