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
impl HeadlessBackend
Sourcepub fn new(width: u16, height: u16) -> (Self, HeadlessHandle)
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
impl Backend for HeadlessBackend
Source§fn draw(&mut self, content: &[(u16, u16, &Cell)])
fn draw(&mut self, content: &[(u16, u16, &Cell)])
Write each changed cell into the internal buffer.
Source§fn set_caret_size(&mut self, size: u8)
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>
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
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>
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>
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
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)
fn size(&self) -> (u16, u16)
(cols, rows). Read moreSource§fn set_cursor(&mut self, pos: Option<(u16, u16)>)
fn set_cursor(&mut self, pos: Option<(u16, u16)>)
pos, or hide it when pos is None.Auto Trait Implementations§
impl !RefUnwindSafe for HeadlessBackend
impl !Send for HeadlessBackend
impl !Sync for HeadlessBackend
impl !UnwindSafe for HeadlessBackend
impl Freeze for HeadlessBackend
impl Unpin for HeadlessBackend
impl UnsafeUnpin for HeadlessBackend
Blanket Implementations§
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<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.