pub struct HeadlessTerm { /* private fields */ }Expand description
A headless terminal for testing without real terminal I/O.
Processes ANSI escape sequences through TerminalModel and provides
assertion helpers, snapshot comparison, and export capabilities.
Implementations§
Source§impl HeadlessTerm
impl HeadlessTerm
Sourcepub fn process(&mut self, bytes: &[u8])
pub fn process(&mut self, bytes: &[u8])
Process raw bytes through the terminal emulator.
Bytes are parsed as ANSI escape sequences and applied to the internal grid, just as a real terminal would.
Sourcepub fn row_text(&self, row: usize) -> String
pub fn row_text(&self, row: usize) -> String
Get the text content of a single row, trimmed of trailing spaces.
Returns an empty string for out-of-bounds rows.
Sourcepub fn screen_text(&self) -> Vec<String>
pub fn screen_text(&self) -> Vec<String>
Get all rows as text, trimmed of trailing spaces.
Sourcepub fn screen_string(&self) -> String
pub fn screen_string(&self) -> String
Get all rows as a single string joined by newlines.
Sourcepub fn model(&self) -> &TerminalModel
pub fn model(&self) -> &TerminalModel
Access the underlying TerminalModel for advanced queries.
Sourcepub fn captured_output(&self) -> &[u8] ⓘ
pub fn captured_output(&self) -> &[u8] ⓘ
Access all captured output bytes (everything passed to process).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the terminal to its initial state (blank screen, cursor at origin).
Sourcepub fn assert_matches(&self, expected: &[&str])
pub fn assert_matches(&self, expected: &[&str])
Assert that the screen content matches the expected lines exactly.
Trailing spaces in both actual and expected lines are trimmed before comparison. The number of expected lines must match the terminal height.
§Panics
Panics with a human-readable diff if the content doesn’t match.
Sourcepub fn assert_row(&self, row: usize, expected: &str)
pub fn assert_row(&self, row: usize, expected: &str)
Assert that a specific row matches the expected text.
Trailing spaces are trimmed before comparison.
§Panics
Panics if the row content doesn’t match.
Sourcepub fn assert_cursor(&self, col: u16, row: u16)
pub fn assert_cursor(&self, col: u16, row: u16)
Assert that the cursor is at the expected position (column, row), 0-indexed.
§Panics
Panics if the cursor position doesn’t match.
Sourcepub fn diff(&self, expected: &[&str]) -> Option<ScreenDiff>
pub fn diff(&self, expected: &[&str]) -> Option<ScreenDiff>
Compare screen content with expected lines and return the diff.
Returns None if the content matches exactly.
Sourcepub fn export(&self, path: &Path) -> Result<()>
pub fn export(&self, path: &Path) -> Result<()>
Export the screen content to a file for debugging.
Writes a human-readable text representation including:
- Terminal dimensions
- Cursor position
- Screen content (with line numbers)
- Captured output size
Sourcepub fn export_string(&self) -> String
pub fn export_string(&self) -> String
Export the screen content as a formatted string (for inline debugging).