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:
- Validates memory integrity before access
- Performs bounds checking on all cell access
- Provides ergonomic, type-safe getters
- Enables testing with mock implementations
Required Methods§
Sourcefn cells(&self) -> &[Cell]
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.
Sourcefn cursor_pos(&self) -> (u16, u16)
fn cursor_pos(&self) -> (u16, u16)
Sourcefn sequence(&self) -> u64
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
Sourcefn is_valid(&self) -> bool
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
Sourcefn dimensions(&self) -> (usize, usize)
fn dimensions(&self) -> (usize, usize)
Sourcefn is_dirty(&self) -> bool
fn is_dirty(&self) -> bool
Check if dirty flag is set
The dirty flag indicates pending updates that haven’t been rendered.
Sourcefn is_error_mode(&self) -> bool
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§
Sourcefn iter_cells(&self) -> CellIterator<'_, Self> ⓘwhere
Self: Sized,
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.