[−][src]Struct crossterm::Terminal
Allows you to preform actions on the terminal.
Features:
- Clearing (all lines, current line, from cursor down and up, until new line)
- Scrolling (Up, down)
- Get the size of the terminal
- Set the size of the terminal
- Alternate screen
- Raw screen
- Exit the current process
Check /examples/
in the library for more specific examples.
Remarks
When you want to perform terminal actions on 'alternate screen' use the 'crossterm_screen' crate.
Methods
impl<'stdout> Terminal<'stdout>
[src]
pub fn new() -> Terminal<'stdout>
[src]
Create new terminal instance whereon terminal related actions can be performed.
pub fn from_output(stdout: &'stdout Arc<TerminalOutput>) -> Terminal<'stdout>
[src]
Create a new instance of Terminal
whereon terminal related actions could be preformed on the given output.
Remarks
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'.
You should checkout the 'crossterm_screen' crate for more information about this.
Example
let screen = Screen::default(); if let Ok(alternate) = screen.enable_alternate_modes(false) { let terminal = Terminal::from_output(&alternate.screen.stdout); }
pub fn clear(&self, clear_type: ClearType) -> Result<(), ErrorKind>
[src]
Clear the current cursor by specifying the ClearType
.
Example
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);
pub fn terminal_size(&self) -> (u16, u16)
[src]
pub fn scroll_up(&self, count: i16) -> Result<(), ErrorKind>
[src]
Scroll n
lines up in the current terminal.
Parameter
count
: the number of rows should be shifted up.
pub fn scroll_down(&self, count: i16) -> Result<(), ErrorKind>
[src]
Scroll n
lines down in the current terminal.
Parameter
count
: the number of rows should be shifted down.
pub fn set_size(&self, width: i16, height: i16) -> Result<(), ErrorKind>
[src]
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);
pub fn exit(&self)
[src]
Exit the current process.
let mut term = terminal(); let size = term.exit();
pub fn write<D>(&self, value: D) -> Result<usize, ErrorKind> where
D: Display,
[src]
D: Display,
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
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,