Skip to main content

TerminalStateReader

Trait TerminalStateReader 

Source
pub trait TerminalStateReader {
    // Required methods
    fn cell(&self, row: usize, col: usize) -> Option<&Cell>;
    fn cells(&self) -> &[Cell];
    fn cursor_pos(&self) -> (u16, u16);
    fn sequence(&self) -> u64;
    fn is_valid(&self) -> bool;
    fn dimensions(&self) -> (usize, usize);
    fn is_dirty(&self) -> bool;
    fn is_error_mode(&self) -> bool;

    // Provided methods
    fn cell_index(&self, row: usize, col: usize) -> Option<usize> { ... }
    fn iter_cells(&self) -> CellIterator<'_, Self> 
       where Self: Sized { ... }
}
Expand description

Safe, validated interface for reading terminal state

This trait provides the abstraction layer over SharedState that:

  1. Validates memory integrity before access
  2. Performs bounds checking on all cell access
  3. Provides ergonomic, type-safe getters
  4. Enables testing with mock implementations

Required Methods§

Source

fn cell(&self, row: usize, col: usize) -> Option<&Cell>

Get cell at position, returns None if out of bounds

§Arguments
  • row - Zero-indexed row (0 to GRID_HEIGHT-1)
  • col - Zero-indexed column (0 to GRID_WIDTH-1)
§Returns
  • Some(&Cell) if position is valid
  • None if out of bounds
Source

fn cells(&self) -> &[Cell]

Get all cells as a slice

Returns the full grid buffer. Prefer using cell() with bounds checking when accessing individual cells.

Source

fn cursor_pos(&self) -> (u16, u16)

Get cursor position

§Returns

Tuple of (x, y) cursor coordinates in grid space

Source

fn sequence(&self) -> u64

Get current sequence number

The sequence number increments with each state update. Clients can poll this to detect changes.

§Returns

Monotonically increasing sequence counter

Source

fn is_valid(&self) -> bool

Check if state is valid

Validates:

  • Magic number matches expected value
  • Memory appears properly initialized
  • Cursor position is within bounds
§Returns

true if state passes validation checks

Source

fn dimensions(&self) -> (usize, usize)

Get grid dimensions

§Returns

Tuple of (width, height) in cells

Source

fn is_dirty(&self) -> bool

Check if dirty flag is set

The dirty flag indicates pending updates that haven’t been rendered.

Source

fn is_error_mode(&self) -> bool

Check if error mode is active

Error mode indicates the daemon encountered a fatal error (PTY/SHM unavailable) and has written an error message to the grid. Clients should display this error and exit gracefully.

§Returns

true if daemon is in error mode

Provided Methods§

Source

fn cell_index(&self, row: usize, col: usize) -> Option<usize>

Get linear cell index from row/col coordinates

§Arguments
  • row - Zero-indexed row
  • col - Zero-indexed column
§Returns
  • Some(index) if coordinates are valid
  • None if out of bounds
Source

fn iter_cells(&self) -> CellIterator<'_, Self>
where Self: Sized,

Iterate over all cells with their coordinates

Yields tuples of (row, col, &Cell) for convenient iteration.

Implementors§