[][src]Struct crossterm::Crossterm

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

Remark

  • 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.

Methods

impl<'crossterm> Crossterm[src]

pub fn new() -> Crossterm[src]

Create a new instance of Crossterm

pub fn from_screen(screen: &Screen) -> Crossterm[src]

Create a new instance of Crossterm

pub fn cursor(&self) -> TerminalCursor[src]

Get a TerminalCursor implementation whereon cursor related actions can be performed.

let crossterm = Crossterm::new();
let cursor = crossterm.cursor();

pub fn input(&self) -> TerminalInput[src]

Get a TerminalInput implementation whereon terminal related actions can be performed.

let crossterm = Crossterm::new();
let input = crossterm.input();

pub fn terminal(&self) -> Terminal[src]

Get a Terminal implementation whereon terminal related actions can be performed.

let crossterm = Crossterm::new();
let mut terminal = crossterm.terminal();

pub fn color(&self) -> TerminalColor[src]

Get a TerminalColor implementation whereon color related actions can be performed.

let crossterm = Crossterm::new();
let mut terminal = crossterm.color();

pub fn style<D>(&self, val: D) -> StyledObject<D> where
    D: Display
[src]

This could be used to style any type implementing Display with colors and attributes.

Example

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

Remark

val: any type implementing Display e.g. string.

pub fn paint<'a, D: Display + 'a>(
    &self,
    styled_object: StyledObject<D>
) -> Result<()>
[src]

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.

Trait Implementations

impl From<Arc<TerminalOutput>> for Crossterm[src]

Auto Trait Implementations

impl Send for Crossterm

impl Sync for Crossterm

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]