Skip to main content

TestTerminal

Struct TestTerminal 

Source
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

Source

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.

Source

pub async fn tick(&mut self) -> Result<(), Error>

Yield so hook-spawned tasks can run, then process wakes and redraw.

Source

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.

Source

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.

Source

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);
Source

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.

Source

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.

Source

pub fn exited(&self) -> bool

Whether the app has called use_app().exit().

Source

pub fn send_key(&mut self, code: KeyCode) -> Result<(), Error>

Sends a key press with no modifiers and redraws.

Source

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.

Source

pub fn send_paste(&mut self, text: &str) -> Result<(), Error>

Dispatches a bracketed-paste event through mounted use_paste handlers, applies any resulting wakes, and redraws.

Source

pub fn clipboard(&self) -> &[String]

Clipboard payloads the app has sent via AppHandle::copy_to_clipboard and that have been flushed to the (test) backend, oldest first.

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.