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 const SPACE_GLYPH: char = '·'
pub const SPACE_GLYPH: char = '·'
The glyph format_view/format_styled render in place of a literal space, so
layout is visible in text diffs.
Public so a caller converting a rendered view back to plain text (or a search needle’s
spaces into the view’s own convention, as TestHarness::find_text does) has
something to match against other than a hardcoded '·' that could silently drift out of
sync with this backend’s actual choice. Prefer TestHarness::readable_view for the
common case of getting a plain string back for .contains/assert_eq! checks.
Sourcepub fn new(width: u16, height: u16) -> Headless
pub fn new(width: u16, height: u16) -> Headless
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
compositing of Compositing::CellFlattened,
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
Compositing::PixelLayered from
compositing 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<u16>
pub const fn cursor_position(&self) -> Pos<u16>
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 push_coalesced), 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<u16>)
fn set_cursor_position(&mut self, position: Pos<u16>)
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<(), <Headless as Output>::Error>
fn draw_layers<'a, I>( &mut self, content: I, ) -> Result<(), <Headless as Output>::Error>
Source§fn flush(&mut self) -> Result<(), <Headless as Output>::Error>
fn flush(&mut self) -> Result<(), <Headless as Output>::Error>
Source§fn clear(&mut self) -> Result<(), <Headless as Output>::Error>
fn clear(&mut self) -> Result<(), <Headless as Output>::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 compositing(&self) -> Compositing
fn compositing(&self) -> Compositing
draw_layers. Read moreAuto Trait Implementations§
impl Freeze for Headless
impl RefUnwindSafe for Headless
impl Send for Headless
impl Sync for Headless
impl Unpin for Headless
impl UnsafeUnpin for Headless
impl UnwindSafe for Headless
Blanket Implementations§
impl<T> Backend for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.