pub struct TestTerminal { /* private fields */ }Expand description
A headless terminal that drives an ntui component tree frame by frame,
for use in tests. Mirrors what crate::render does against a real
terminal, but under manual control and without crossterm I/O.
Implementations§
Source§impl TestTerminal
impl TestTerminal
Sourcepub fn new(width: u16, height: u16, el: Element) -> Result<Self, Error>
pub fn new(width: u16, height: u16, el: Element) -> Result<Self, Error>
Mounts el at width x height, processes any mount-time wakes,
and renders the first frame.
Sourcepub async fn tick(&mut self) -> Result<(), Error>
pub async fn tick(&mut self) -> Result<(), Error>
Yield so hook-spawned tasks can run, then process wakes and redraw.
Sourcepub fn resize(&mut self, width: u16, height: u16) -> Result<(), Error>
pub fn resize(&mut self, width: u16, height: u16) -> Result<(), Error>
Resizes the virtual terminal and redraws a full frame at the new size. Clipboard history is kept across the resize.
Sourcepub fn frame_text(&self) -> String
pub fn frame_text(&self) -> String
The current frame as a plain-text grid.
Styling is not represented. To assert on color, weight, or
background — a selected row’s highlight, a marked column header —
use TestTerminal::cell or TestTerminal::buffer.
Sourcepub fn cell(&self, x: u16, y: u16) -> Option<Cell>
pub fn cell(&self, x: u16, y: u16) -> Option<Cell>
The painted cell at x, y, with its colors and attributes.
None when the coordinates are outside the terminal.
let t = TestTerminal::new(5, 1, element!(Text(content: "hi", color: Color::Red))).unwrap();
assert_eq!(t.cell(0, 0).unwrap().ch, 'h');
assert_eq!(t.cell(0, 0).unwrap().fg, Color::Red);Sourcepub fn buffer(&self) -> &Buffer
pub fn buffer(&self) -> &Buffer
The whole painted frame, styling included.
frame_text is the readable view of the
same data; this is the one to reach for when the property under test
is visual rather than textual.
Sourcepub fn row(&self, y: u16) -> Vec<Cell>
pub fn row(&self, y: u16) -> Vec<Cell>
The cells of row y, left to right. Empty if y is off-screen.
Convenient for asserting that a whole row shares a background — the usual shape of a selection highlight.
Sourcepub fn send_key(&mut self, code: KeyCode) -> Result<(), Error>
pub fn send_key(&mut self, code: KeyCode) -> Result<(), Error>
Sends a key press with no modifiers and redraws.
Sourcepub fn send_key_event(&mut self, ev: KeyEvent) -> Result<(), Error>
pub fn send_key_event(&mut self, ev: KeyEvent) -> Result<(), Error>
Dispatches a key event through mounted use_input handlers, applies
any resulting wakes, and redraws.