pub struct Headless { /* private fields */ }Expand description
In-memory backend for testing.
Stores presented content and allows injecting synthetic events.
Implementations§
Source§impl Headless
impl Headless
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
Creates a new headless backend of the given dimensions.
Sourcepub fn grid(&self) -> &Grid
pub fn grid(&self) -> &Grid
Returns the composited frame: every layer this backend has been sent, flattened into a
single layer under the TileFlags::EMPTY transparency rule
documented on crate::grid.
For the usual case, a backend left at the default
composites_layers of false,
crate::terminal::Terminal::present has already flattened the frame and only layer 0 is
ever written, so this is simply the received content. Use
layer_grid to inspect the raw per-layer state instead.
Sourcepub const fn layer_grid(&self) -> &Grid
pub const fn layer_grid(&self) -> &Grid
Returns the raw, un-composited per-layer state, as received.
Only interesting for a backend wrapping this one that returns true from
composites_layers and so receives the multi-layer stream:
this is what lets a test assert which layer a cell arrived on, rather than only what the
composited frame looks like. Otherwise identical to grid.
Sourcepub const fn cursor_visible(&self) -> bool
pub const fn cursor_visible(&self) -> bool
Returns the cursor visibility.
Sourcepub const fn cursor_position(&self) -> Pos
pub const fn cursor_position(&self) -> Pos
Returns the cursor position.
Sourcepub const fn cursor_style(&self) -> CursorStyle
pub const fn cursor_style(&self) -> CursorStyle
Returns the cursor’s shape and blink behavior, as last set by
Cursor::set_cursor_style.
Sourcepub fn push_event(&mut self, event: Event)
pub fn push_event(&mut self, event: Event)
Injects a synthetic event into the queue.
Coalesces consecutive Mouse(Moved) or same-button Mouse(Drag) events with the queue’s
current tail (see coalesces_with), matching the retroglyph-window and
retroglyph-terminal-wasm backends this stands in for during tests (retroglyph#768): a
caller pushing a burst of pointer positions before draining the queue sees only the latest
one, the same as it would against a real backend.
Sourcepub fn format_view(&self) -> String
pub fn format_view(&self) -> String
Converts the current grid state into a readable string for snapshot testing.
Space cells are rendered as · so layout is visible in text diffs.
Sourcepub fn format_styled(&self) -> String
pub fn format_styled(&self) -> String
format_view, with each cell’s colors emitted as SGR (ANSI) escape sequences.
Suitable for insta::assert_snapshot!, which renders ANSI in its terminal diff output:
a color regression that format_view can’t see (two styles that share a glyph) shows up
as a snapshot diff here. Spacer cells (the trailing half of a wide glyph) are blanked the
same way format_view blanks them, with no style of their own.
Each run of cells that share a Style is wrapped in a \x1b[0m reset followed by the
SGR codes for that style’s non-default foreground/background; a bare Style::default()
run only gets the reset. This keeps every row self-contained (no state leaks across rows
or into terminals that render the snapshot directly).
Color::Ansi and Color::Indexed map to their standard SGR codes (30-37/90-97 and
38;5;n/48;5;n); Color::Rgb maps to 24-bit SGR (38;2;r;g;b/48;2;r;g;b) rather
than being downgraded, so this reflects the style as authored, not as a particular
terminal would render it.
Trait Implementations§
Source§impl Cursor for Headless
impl Cursor for Headless
Source§fn set_cursor_visible(&mut self, visible: bool)
fn set_cursor_visible(&mut self, visible: bool)
Source§fn set_cursor_position(&mut self, position: Pos)
fn set_cursor_position(&mut self, position: Pos)
Source§fn set_cursor_style(&mut self, style: CursorStyle)
fn set_cursor_style(&mut self, style: CursorStyle)
Source§impl Output for Headless
impl Output for Headless
Source§type Error = Infallible
type Error = Infallible
Source§fn draw_layers<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
fn draw_layers<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
Source§fn flush(&mut self) -> Result<(), Self::Error>
fn flush(&mut self) -> Result<(), Self::Error>
Source§fn draw<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
fn draw<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
Source§fn needs_full_frame(&self) -> bool
fn needs_full_frame(&self) -> bool
true if the backend needs the entire frame (all cells on
all layers) on every call to draw_layers, rather
than just the changed cells. Read moreSource§fn composites_layers(&self) -> bool
fn composites_layers(&self) -> bool
draw_layers. Read more