Skip to main content

Headless

Struct Headless 

Source
pub struct Headless { /* private fields */ }
Expand description

In-memory backend for testing.

Stores presented content and allows injecting synthetic events.

Implementations§

Source§

impl Headless

Source

pub fn new(width: u16, height: u16) -> Self

Creates a new headless backend of the given dimensions.

Source

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.

Source

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.

Source

pub const fn cursor_visible(&self) -> bool

Returns the cursor visibility.

Source

pub const fn cursor_position(&self) -> Pos

Returns the cursor position.

Source

pub const fn cursor_style(&self) -> CursorStyle

Returns the cursor’s shape and blink behavior, as last set by Cursor::set_cursor_style.

Source

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.

Source

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.

Source

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

Source§

fn set_cursor_visible(&mut self, visible: bool)

Show or hide the cursor.
Source§

fn set_cursor_position(&mut self, position: Pos)

Move the cursor to a position.
Source§

fn set_cursor_style(&mut self, style: CursorStyle)

Set the cursor’s shape (and blink behavior). Read more
Source§

impl Input for Headless

Source§

fn poll_event(&mut self, _timeout: Duration) -> Option<Event>

Poll for an input event, waiting up to timeout.
Source§

fn push_event(&mut self, event: Event)

Push an event into the backend’s event buffer. Read more
Source§

impl Output for Headless

Source§

type Error = Infallible

Error type returned by fallible operations.
Source§

fn draw_layers<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
where I: Iterator<Item = DrawCell<'a>>,

Draw changed cells across all layers. Read more
Source§

fn resize(&mut self, size: Size)

Notify the backend of a resize to size, updating what size reports. Read more
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Flush buffered output to the display. Read more
Source§

fn size(&self) -> Size

Return current display dimensions.
Source§

fn clear(&mut self) -> Result<(), Self::Error>

Clear the entire display. Read more
Source§

fn draw<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
where I: Iterator<Item = DrawCell<'a>>,

Draw changed cells to the output surface, layer 0 only. Read more
Source§

fn needs_full_frame(&self) -> bool

Returns 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 more
Source§

fn composites_layers(&self) -> bool

Whether this backend composites layers itself (per pixel or quad), receiving the raw layered stream from draw_layers. Read more

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Backend for T
where T: Output + Input + Cursor,