Skip to main content

TerminalModel

Struct TerminalModel 

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

A minimal terminal model for testing presenter output.

Tracks grid state, cursor position, SGR state, and hyperlinks. Processes a subset of ANSI sequences that we emit.

Implementations§

Source§

impl TerminalModel

Source

pub fn new(width: usize, height: usize) -> Self

Create a new terminal model with the given dimensions.

Dimensions are clamped to a minimum of 1×1 to prevent arithmetic underflows in cursor-positioning and diff helpers.

Source

pub fn width(&self) -> usize

Get the terminal width.

Source

pub fn height(&self) -> usize

Get the terminal height.

Source

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

Get the cursor position as (x, y).

Source

pub fn sgr_state(&self) -> &SgrState

Get the current SGR state.

Source

pub fn modes(&self) -> &ModeFlags

Get the current mode flags.

Source

pub fn cell(&self, x: usize, y: usize) -> Option<&ModelCell>

Get the cell at (x, y). Returns None if out of bounds.

Source

pub fn current_cell(&self) -> Option<&ModelCell>

Get the current cell under the cursor.

Source

pub fn cells(&self) -> &[ModelCell]

Get all cells as a slice.

Source

pub fn row(&self, y: usize) -> Option<&[ModelCell]>

Get a row of cells.

Source

pub fn row_text(&self, y: usize) -> Option<String>

Extract the text content of a row as a string (trimmed of trailing spaces).

Get the URL for a link ID.

Check if the terminal has a dangling hyperlink (active link after processing).

Source

pub fn sync_output_balanced(&self) -> bool

Check if synchronized output is properly balanced.

Source

pub fn reset(&mut self)

Reset the terminal model to initial state.

Source

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

Process a byte sequence, updating the terminal state.

Source

pub fn diff_grid(&self, expected: &[ModelCell]) -> Option<String>

Compare two grids and return a diff description for debugging.

Source

pub fn dump_sequences(bytes: &[u8]) -> String

Dump the escape sequences in a human-readable format (for debugging test failures).

Trait Implementations§

Source§

impl Debug for TerminalModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.