pub struct Term { /* private fields */ }Expand description
A minimal VT100/ECMA-48 terminal emulator over an ansi::Screen.
Implementations§
Source§impl Term
impl Term
Sourcepub fn can_checkpoint(&self) -> bool
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.
Sourcepub fn checkpoint(&self) -> Option<Vec<u8>>
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.
Sourcepub fn restore(bytes: &[u8]) -> Result<Term, RestoreError>
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
impl Term
Sourcepub fn new(rows: usize, cols: usize) -> Self
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.
Sourcepub fn with_history(rows: usize, cols: usize, lines: usize) -> Self
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.
Sourcepub fn feed(&mut self, bytes: &[u8])
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.
Sourcepub fn take_dirty(&mut self) -> bool
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.
Sourcepub fn screen(&self) -> &Screen
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.
Sourcepub fn scrollback(&self) -> &Screen
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.
Sourcepub fn set_history_bytes(&mut self, max: usize)
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.
Sourcepub fn in_alternate_screen(&self) -> bool
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.
Sourcepub fn cursor_visible(&self) -> bool
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.
Sourcepub fn bracketed_paste(&self) -> bool
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~.
Sourcepub fn mouse_tracking(&self) -> MouseTracking
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.
Sourcepub fn mouse_sgr(&self) -> bool
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).
Sourcepub fn in_sync(&self) -> bool
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.