Skip to main content

Term

Struct Term 

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

A minimal VT100/ECMA-48 terminal emulator over an ansi::Screen.

Implementations§

Source§

impl Term

Source

pub fn can_checkpoint(&self) -> bool

True when a checkpoint can be taken now: the tokenizer is between sequences and no UTF-8 character is half-decoded.

Source

pub fn checkpoint(&self) -> Option<Vec<u8>>

The emulator’s whole state as bytes, or None if a sequence or character is in progress (can_checkpoint). Deterministic: equal states give equal bytes.

Source

pub fn restore(bytes: &[u8]) -> Result<Term, RestoreError>

Rebuild an emulator from checkpoint bytes. Feeding it the same bytes afterwards gives the same result as feeding the original. Bad input is an error, never a panic.

Source§

impl Term

Source

pub fn new(rows: usize, cols: usize) -> Self

A blank emulator of rows x cols (both clamped to at least 1), cursor at the origin, full-height scroll region, default tab stops every 8 columns, autowrap on, cursor visible.

Source

pub fn with_history(rows: usize, cols: usize, lines: usize) -> Self

Like Term::new, keeping up to lines lines that scroll off the top of the primary screen, readable through Term::scrollback. Each line is stored compactly as it leaves (ansi::Screen::with_history: its text plus runs of style, not a row of cells), so memory follows the text held rather than lines x cols. The alternate screen, and scroll regions, keep no history.

Source

pub fn feed(&mut self, bytes: &[u8])

Feed a chunk of child output. Chunks may split at any byte boundary (mid-escape, mid-UTF-8); the internal parser holds partial state across calls, so the final screen is independent of how bytes were chunked.

Source

pub fn take_dirty(&mut self) -> bool

Returns true if any bytes have been fed (or a resize has occurred) since the last call to take_dirty, and resets the flag. Call once per frame decision to avoid redundant compositing.

Source

pub fn screen(&self) -> &Screen

The active buffer (alternate while in alt-screen, else primary). Its cursor is the emulator’s cursor, so a compositor / Screen::diff parks the terminal cursor correctly.

Source

pub fn scrollback(&self) -> &Screen

The primary screen, whose history (ansi::Screen::history_len, ansi::Screen::history_row) holds the lines scrolled off its top. Empty unless made with Term::with_history.

Source

pub fn set_history_bytes(&mut self, max: usize)

Cap the scrollback at max bytes as stored (0: no cap), dropping the oldest lines past it (ansi::Screen::set_history_bytes): a memory bound however wide or colourful lines are. Kept across resizes.

Source

pub fn in_alternate_screen(&self) -> bool

True while the alternate screen is active (full-screen programs), where scrolling back through history does not apply.

Source

pub fn cursor_visible(&self) -> bool

Whether the program has the cursor shown (?25h, the default) or hidden (?25l), for the host to draw it or not.

Source

pub fn bracketed_paste(&self) -> bool

Whether the program asked for bracketed paste (?2004h): the host then wraps what it pastes in ESC [200~ and ESC [201~.

Source

pub fn mouse_tracking(&self) -> MouseTracking

Which mouse events the program asked to be sent (?1000h clicks, ?1002h also drags, ?1003h also any motion); the host reports them instead of using the mouse itself.

Source

pub fn mouse_sgr(&self) -> bool

Whether mouse reports use the SGR encoding (?1006h, ESC [< b ; x ; y M), else the original one (ESC [M and three bytes, for positions up to 223).

Source

pub fn in_sync(&self) -> bool

True while the child is inside a synchronized update (DEC mode 2026): it has emitted ?2026h and not yet the matching ?2026l. During this window Term::screen returns the last complete frame. Exposed so a host can also gate its own compositing on it if desired.

Source

pub fn resize(&mut self, rows: usize, cols: usize)

Resize to rows x cols (clamped to at least 1). For 0.1 this rebuilds fresh buffers of the new size (the caller repaints); the cursor and scroll region are clamped, tab stops rebuilt, and pending wrap cleared.

Auto Trait Implementations§

§

impl Freeze for Term

§

impl RefUnwindSafe for Term

§

impl Send for Term

§

impl Sync for Term

§

impl Unpin for Term

§

impl UnsafeUnpin for Term

§

impl UnwindSafe for Term

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.