Guide API
Skip to main content

HeadlessBackend

Struct HeadlessBackend 

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

In-memory backend for deterministic tests.

HeadlessBackend stores an in-memory cell buffer and a programmable event queue. It never performs I/O and never blocks. Create it with HeadlessBackend::new; move the backend into a Renderer and keep the returned HeadlessHandle to inject events and inspect the screen after each Renderer::render call.

The shared-state pattern avoids downcasting: the handle and the backend share the same Rc<RefCell<…>> cells, so tests can observe the screen without needing to reach through the Box<dyn Backend> that the Renderer owns.

§Turbo Vision heritage

tvision-rs extension: no Turbo Vision counterpart. It stands in for the platform terminal driver so the snapshot test suite, or an application’s own tests, can drive the framework synchronously, with injected input and an inspectable screen (deviation D11).

Implementations§

Source§

impl HeadlessBackend

Source

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

Create a width × height headless backend.

Returns (backend, handle): move backend into a Renderer and retain handle to inspect the screen and inject input. Call HeadlessHandle::resize on the handle to simulate a terminal resize; the next pump_once will detect the change and relay it through the view tree via each child’s grow-mode.

Trait Implementations§

Source§

impl Backend for HeadlessBackend

Source§

fn draw(&mut self, content: &[(u16, u16, &Cell)])

Write each changed cell into the internal buffer.

Source§

fn flush(&mut self)

No-op: headless has no output stream.

Source§

fn set_caret_size(&mut self, size: u8)

Record the caret size for HeadlessHandle::caret_size.

Source§

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

Pop the front event from the queue, or None if the queue is empty.

Never blocks regardless of timeout. This is the determinism contract: tests drive the loop synchronously by pre-loading events.

Source§

fn set_clipboard(&mut self, text: &str) -> bool

Store text in the shared internal buffer; always returns false.

Headless deliberately does not run the production ClipboardChain — it is the test fake: no OS clipboard, no OSC 52 bytes, just a plain string tests can read via HeadlessHandle::clipboard and seed via HeadlessHandle::set_clipboard.

Source§

fn get_clipboard(&mut self) -> Option<String>

Return the most recently stored clipboard text, or None if nothing has been written.

Source§

fn get_primary(&mut self) -> Option<String>

The staged PRIMARY selection — the test fake for a display server that already owns one.

Source§

fn set_primary(&mut self, text: &str) -> bool

Record the PRIMARY selection so a test can assert what was published. Returns true: headless always “owns” the selection successfully.

Source§

fn size(&self) -> (u16, u16)

Live terminal dimensions in cells, returned as (cols, rows). Read more
Source§

fn set_cursor(&mut self, pos: Option<(u16, u16)>)

Show the hardware cursor at pos, or hide it when pos is None.
Source§

fn suspend(&mut self)

Suspend the terminal: leave alt-screen and restore normal terminal mode. Read more
Source§

fn resume(&mut self)

Resume the terminal: re-enter alt-screen, raw mode, and mouse capture. 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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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.