Skip to main content

Headless

Struct Headless 

Source
pub struct Headless {
    grid: Grid,
    cursor_visible: bool,
    cursor_pos: Pos,
    event_queue: VecDeque<Event>,
}
Expand description

In-memory backend for testing. Stores presented content and allows injecting synthetic events.

Fields§

§grid: Grid§cursor_visible: bool§cursor_pos: Pos§event_queue: VecDeque<Event>

Implementations§

Source§

impl Headless

Source

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

Creates a new headless backend of the given dimensions.

Source

pub const fn grid(&self) -> &Grid

Returns a reference to the 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 fn push_event(&mut self, event: Event)

Injects a synthetic event into the queue.

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.

Trait Implementations§

Source§

impl Backend for Headless

Source§

fn draw<'a, I>(&mut self, content: I)
where I: Iterator<Item = (Pos, &'a Tile)>,

Draw changed cells to the output surface.
Source§

fn resize(&mut self, size: Size)

Notify the backend of a terminal resize. Read more
Source§

fn flush(&mut self)

Flush buffered output to the display.
Source§

fn size(&self) -> Size

Return current display dimensions.
Source§

fn clear(&mut self)

Clear the entire display.
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§

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 draw_layers<'a, I>(&mut self, content: I)
where I: Iterator<Item = (u8, Pos, &'a Tile)>,

Draw changed cells across all layers. 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 is_connected(&self) -> bool

Returns false if the backend has been disconnected from its output (e.g. the window was closed). The game loop should terminate when this returns false. 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.