pub struct Terminal<'stdout> { /* private fields */ }
Expand description
Struct that stores a platform-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’ related 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 from_output(stdout: &'stdout Arc<TerminalOutput>) -> Terminal<'stdout>
pub fn from_output(stdout: &'stdout Arc<TerminalOutput>) -> Terminal<'stdout>
Create a new instance of Terminal
whereon terminal related actions could be preformed on the given output.
Note
Use this function when you want your terminal to operate with a specific output.
This could be useful when you have a screen which is in ‘alternate mode’.
And you want your actions from the Terminal
, created by this function, to operate on the ‘alternate screen’.
Example
let screen = Screen::default();
if let Ok(alternate) = screen.enable_alternate_modes(false) {
let terminal = Terminal::from_output(&alternate.screen.stdout);
}
sourcepub fn clear(&self, clear_type: ClearType) -> Result<(), ErrorKind>
pub fn clear(&self, clear_type: ClearType) -> Result<(), ErrorKind>
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) -> Result<(), ErrorKind>
pub fn scroll_up(&self, count: i16) -> Result<(), ErrorKind>
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) -> Result<(), ErrorKind>
pub fn scroll_down(&self, count: i16) -> Result<(), ErrorKind>
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) -> Result<(), ErrorKind>
pub fn set_size(&self, width: i16, height: i16) -> Result<(), ErrorKind>
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);