pub struct Terminal<'stdout> { /* private fields */ }
Expand description

Struct that stores an specific platform implementation for terminal related actions.

Check /examples/terminal in the library for more specific examples.

use crossterm::terminal;

let term = terminal();

term.scroll_down(5);
term.scroll_up(4);
let (with, height) = term.terminal_size();

When you want to use 'terminal' actions on 'alternate screen' use the `Screen` type instead, and pass it to the `terminal::from_screen()` function.
By doing that terminal actions will be performed on the alternate screen.

Implementations§

Create new terminal instance whereon terminal related actions can be performed.

Create new instance of TerminalInput whereon input related actions could be preformed.

Clear the current cursor by specifying the clear type.

let mut term = terminal();

// clear all cells in terminal.
term.clear(terminal::ClearType::All);
// clear all cells from the cursor position downwards in terminal.
term.clear(terminal::ClearType::FromCursorDown);
// clear all cells from the cursor position upwards in terminal.
term.clear(terminal::ClearType::FromCursorUp);
// clear current line cells in terminal.
term.clear(terminal::ClearType::CurrentLine);
// clear all cells from cursor position until new line in terminal.
term.clear(terminal::ClearType::UntilNewLine);

Get the terminal size (x,y).

let mut term = terminal();

let size = term.terminal_size();
println!("{:?}", size);

Scroll n lines up in the current terminal.

let mut term = terminal();

// scroll up by 5 lines
let size = term.scroll_up(5);

Scroll n lines up in the current terminal.

let mut term = terminal();

// scroll down by 5 lines
let size = term.scroll_down(5);

Set the terminal size. Note that not all terminals can be set to a very small scale.

let mut term = terminal();

// Set of the size to X: 10 and Y: 10
let size = term.set_size(10,10);

Exit the current process.

let mut term = terminal();

let size = term.exit();

Write any displayable content to the current terminal screen.

let mut term = terminal();

let size = term.write("Some text \n Some text on new line");

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.