Struct Terminal

Source
pub struct Terminal { /* private fields */ }
Expand description

A terminal.

The Terminal instance is stateless and does not hold any data. You can create as many instances as you want and they will always refer to the same terminal.

§Examples

Basic usage:

use crossterm_terminal::{Result, Terminal};

fn main() -> Result<()> {
    let terminal = Terminal::new();
    let (cols, rows) = terminal.size()?;

    terminal.set_size(10, 10)?;
    terminal.scroll_up(5)?;

    terminal.set_size(cols, rows)
}

Implementations§

Source§

impl Terminal

Source

pub fn new() -> Terminal

Creates a new Terminal.

Source

pub fn clear(&self, clear_type: ClearType) -> Result<()>

Clears the terminal.

See the ClearType enum to learn about all ways how the terminal can be cleared.

Source

pub fn size(&self) -> Result<(u16, u16)>

Returns the terminal size ((columns, rows)).

Source

pub fn scroll_up(&self, row_count: u16) -> Result<()>

Scrolls the terminal row_count rows up.

Source

pub fn scroll_down(&self, row_count: u16) -> Result<()>

Scrolls the terminal row_count rows down.

Source

pub fn set_size(&self, columns: u16, rows: u16) -> Result<()>

Sets the terminal size.

Source

pub fn exit(&self)

Exits the current process.

§Platform-specific Behavior

std::process::exit is called internally with platform specific exit codes.

Unix: exit code 0.

Windows: exit code 256.

Source

pub fn write<D: Display>(&self, value: D) -> Result<usize>

Writes any displayable content to the current terminal and flushes the standard output.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.