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§
source§impl<'stdout> Terminal<'stdout>
impl<'stdout> Terminal<'stdout>
sourcepub fn new() -> Terminal<'stdout>
pub fn new() -> Terminal<'stdout>
Create new terminal instance whereon terminal related actions can be performed.
sourcepub fn on_screen(stdout: &'stdout Arc<TerminalOutput>) -> Terminal<'stdout>
pub fn on_screen(stdout: &'stdout Arc<TerminalOutput>) -> Terminal<'stdout>
Create new instance of TerminalInput whereon input related actions could be preformed.
sourcepub fn clear(&self, clear_type: ClearType)
pub fn clear(&self, clear_type: ClearType)
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);
sourcepub fn terminal_size(&self) -> (u16, u16)
pub fn terminal_size(&self) -> (u16, u16)
Get the terminal size (x,y).
let mut term = terminal();
let size = term.terminal_size();
println!("{:?}", size);
sourcepub fn scroll_up(&self, count: i16)
pub fn scroll_up(&self, count: i16)
Scroll n
lines up in the current terminal.
let mut term = terminal();
// scroll up by 5 lines
let size = term.scroll_up(5);
sourcepub fn scroll_down(&self, count: i16)
pub fn scroll_down(&self, count: i16)
Scroll n
lines up in the current terminal.
let mut term = terminal();
// scroll down by 5 lines
let size = term.scroll_down(5);
sourcepub fn set_size(&self, width: i16, height: i16)
pub fn set_size(&self, width: i16, height: i16)
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);