Expand description
Test utilities for components built with this crate.
Requires feature testing.
§TestTerminal
A virtual terminal buffer that captures writes and parses ANSI escape sequences. Use it to assert on rendered output without a real terminal:
use tui::testing::{TestTerminal, assert_buffer_eq, render_component};
use tui::{Frame, Line, ViewContext};
let terminal = render_component(
|ctx: &ViewContext| Frame::new(vec![Line::new("hello")]),
80, 24,
);
assert_buffer_eq(&terminal, &["hello"]);TestTerminal implements std::io::Write and tracks cursor position, SGR styles, and scrollback — including delayed (DEC-style) wrapping behavior.
§Helper functions
render_component(f, width, rows)— Render a closure through aRendererinto aTestTerminal.render_component_with_renderer(f, renderer, width, rows)— Same, but reuse an existing renderer (useful for testing frame diffs).render_lines(lines, width, rows)— Render a slice ofLines into aTestTerminal.key(code)— Create aKeyEventwith no modifiers for test input.sample_options()— Returns aVec<SelectOption>with three entries (“Alpha”, “Beta”, “Gamma”).assert_buffer_eq(terminal, expected)— Assert that the terminal buffer matches expected row strings.
§Cell
A single cell in the TestTerminal buffer, storing a char and its Style. Access cells through TestTerminal::buffer() for fine-grained style assertions.
Structs§
- Cell
- A single cell in the terminal buffer, storing both a character and its style.
- Test
Terminal - A virtual terminal buffer for testing terminal output. Captures all writes, tracks cursor position, and parses ANSI escape sequences including SGR (Select Graphic Rendition) codes for style tracking.
Functions§
- assert_
buffer_ eq - Asserts a test terminal buffer matches the expected output. Each element of the expected vector represents a row. Trailing whitespace is ignored on each line.
- cols
- key
- pad
- render_
component - render_
component_ with_ renderer - render_
lines - sample_
options