Struct libterm::Terminal

source ·
pub struct Terminal {
    pub window: Window,
    pub cursor: Cursor,
    /* private fields */
}
Expand description

An instance of a graphical terminal emulator.

Fields§

§window: Window

The terminal’s own window.

§cursor: Cursor

The cursor of the terminal.

Implementations§

source§

impl Terminal

Private methods of Terminal.

source

pub fn get_text_dimensions(&self) -> (usize, usize)

Gets the width and height of the text displayable in number of characters.

source§

impl Terminal

Public methods of Terminal.

source

pub fn new() -> Result<Terminal, &'static str>

Creates a new terminal and adds it to the window manager wm_mutex

source

pub fn print_to_terminal(&mut self, s: String)

Adds a string to be printed to the terminal to the terminal scrollback buffer. Note that one needs to call refresh_display to get things actually printed.

source

pub fn refresh_display(&mut self) -> Result<(), &'static str>

Actually refresh the screen. Currently it’s expensive.

source

pub fn insert_char( &mut self, c: char, offset_from_end: usize ) -> Result<(), &'static str>

Insert a character to the terminal.

Arguments
  • c: the new character to insert.
  • offset_from_end: the position to insert the character. It represents the distance relative to the end of the whole output in the terminal in number of characters.
Examples
  • terminal.insert_char(char, 0) will append char to the end of existing text.
  • terminal.insert_char(char, 5) will insert char right before the last 5 characters.

After invoke this function, one must call refresh_display to get the updates actually showed on the screen.

source

pub fn remove_char( &mut self, offset_from_end: usize ) -> Result<(), &'static str>

Remove a character from the terminal.

Arguments
  • offset_from_end: the position of the character to remove. It represents the distance relative to the end of the whole output in the terminal in number of characters. offset_from_end == 0 is invalid here.
Examples
  • terminal.remove_char(1) will remove the last character in the screen.

After invoke this function, one must call refresh_display to get the updates actually showed on the screen.

source

pub fn move_screen_to_begin(&mut self) -> Result<(), &'static str>

Scroll the screen to the very beginning.

source

pub fn move_screen_to_end(&mut self) -> Result<(), &'static str>

Scroll the screen to the very end.

source

pub fn move_screen_line_up(&mut self) -> Result<(), &'static str>

Scroll the screen a line up.

source

pub fn move_screen_line_down(&mut self) -> Result<(), &'static str>

Scroll the screen a line down.

source

pub fn move_screen_page_up(&mut self) -> Result<(), &'static str>

Scroll the screen a page up.

source

pub fn move_screen_page_down(&mut self) -> Result<(), &'static str>

Scroll the screen a page down.

source

pub fn clear(&mut self)

Clear the scrollback buffer and reset the scroll positions.

source

pub fn get_event(&mut self) -> Option<Event>

Gets an event from the window’s event queue.

Returns None if no events have been sent to this window.

source

pub fn display_cursor(&mut self) -> Result<(), &'static str>

Display the cursor of the terminal.

source

pub fn get_cursor_offset_from_end(&self) -> usize

Gets the position of the cursor relative to the end of text in number of characters.

source

pub fn update_cursor_pos(&mut self, offset_from_end: usize, underlying_char: u8)

Updates the position of a cursor.

Arguments
  • offset_from_end: the position of the cursor relative to the end of text in number of characters.
  • underlying_char: the ASCII code of the underlying character when the cursor is unseen.
source

pub fn resize(&mut self, new_position: Rectangle) -> Result<(), &'static str>

Resizes this terminal and its underlying text display and then refreshes the window. This does not automatically redisplay the terminal cursor.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.