pub struct Terminal<'stdout> { /* fields omitted */ }
Allows you to preform actions on the terminal.
- 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.
When you want to perform terminal actions on 'alternate screen' use the 'crossterm_screen' crate.
Create new terminal instance whereon terminal related actions can be performed.
Create a new instance of Terminal
whereon terminal related actions could be preformed on the given output.
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.
let screen = Screen::default();
if let Ok(alternate) = screen.enable_alternate_modes(false) {
let terminal = Terminal::from_output(&alternate.screen.stdout);
}
Clear the current cursor by specifying the ClearType
.
let mut term = terminal();
term.clear(terminal::ClearType::All);
term.clear(terminal::ClearType::FromCursorDown);
term.clear(terminal::ClearType::FromCursorUp);
term.clear(terminal::ClearType::CurrentLine);
term.clear(terminal::ClearType::UntilNewLine);
Get the terminal size (x,y).
This will return a tuple of (x: u16, y: u16)
Scroll n
lines up in the current terminal.
count
: the number of rows should be shifted up.
Scroll n
lines down in the current terminal.
count
: the number of rows should be shifted down.
Set the terminal size. Note that not all terminals can be set to a very small scale.
let mut term = terminal();
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");
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)