pub struct HeadlessHandle { /* private fields */ }Expand description
A cloneable window into a HeadlessBackend’s screen and event queue.
Retain this value after constructing the backend with HeadlessBackend::new
— the backend is then boxed and given to the Renderer.
The handle outlives that move and lets tests inspect or drive the backend:
let (backend, screen) = HeadlessBackend::new(80, 25);
let mut renderer = Renderer::new(Box::new(backend));
// … render frames …
let _ = screen.snapshot();Implementations§
Source§impl HeadlessHandle
impl HeadlessHandle
Sourcepub fn snapshot(&self) -> String
pub fn snapshot(&self) -> String
The golden-snapshot string of the current screen.
Delegates to crate::screen::snapshot::snapshot, which produces the
frozen size / cursor / text / attr / legend format documented on that
module. Pass the result to insta::assert_snapshot!.
Sourcepub fn push_event(&self, ev: Event)
pub fn push_event(&self, ev: Event)
Queue an input event to be returned by the next poll_event.
Sourcepub fn push_key(&self, key: Key, modifiers: KeyModifiers)
pub fn push_key(&self, key: Key, modifiers: KeyModifiers)
Convenience: queue a Event::KeyDown event.
Builds a KeyEvent from key and modifiers and pushes
Event::KeyDown(…) onto the queue.
Sourcepub fn push_paste(&self, text: impl Into<String>)
pub fn push_paste(&self, text: impl Into<String>)
Queue a bracketed-paste event. Equivalent to the terminal delivering
an EnableBracketedPaste-wrapped paste sequence.
Sourcepub fn buffer(&self) -> Ref<'_, Buffer>
pub fn buffer(&self) -> Ref<'_, Buffer>
Borrow the current screen buffer (for assertions beyond the snapshot).
Sourcepub fn cursor(&self) -> Option<(u16, u16)>
pub fn cursor(&self) -> Option<(u16, u16)>
The current cursor position: Some((x, y)) when visible, None when hidden.
Sourcepub fn caret_size(&self) -> u8
pub fn caret_size(&self) -> u8
The caret size last set by the renderer (see
Backend::set_caret_size);
CARET_NORMAL until a caret is shown.
Sourcepub fn clipboard(&self) -> Option<String>
pub fn clipboard(&self) -> Option<String>
The backend’s clipboard text, or None if nothing has been written or
the stored text is empty (an empty string is indistinguishable from
never-written — mirroring ClipboardChain::get’s empty→None) —
lets tests assert what a copy path (Deferred::SetClipboard) stored.
Sourcepub fn set_clipboard(&self, text: &str)
pub fn set_clipboard(&self, text: &str)
Seed the backend clipboard — lets tests stage text for a paste path
(Deferred::EditorPaste) without going through set_clipboard.
Sourcepub fn primary(&self) -> Option<String>
pub fn primary(&self) -> Option<String>
The backend’s PRIMARY selection, or None when nothing has been
selected (empty→None, matching clipboard) — lets
tests assert what a mouse selection published.
Sourcepub fn set_primary(&self, text: &str)
pub fn set_primary(&self, text: &str)
Seed the PRIMARY selection — stages the “another X client owns a selection” state a middle-click paste reads.
Sourcepub fn resize(&self, width: u16, height: u16)
pub fn resize(&self, width: u16, height: u16)
Simulate a terminal resize.
Updates the shared size cell and pre-resizes the shared screen buffer so
that the next pump_once resize check (backend.size() ≠ current group
bounds) detects the change and calls group.change_bounds /
renderer.resize, relaying the resize to all child views through their
grow-modes.
The shared buffer is cleared to blank cells at the new size so
backend.draw() can safely write any cell within the new bounds.
Trait Implementations§
Source§impl Clone for HeadlessHandle
impl Clone for HeadlessHandle
Source§fn clone(&self) -> HeadlessHandle
fn clone(&self) -> HeadlessHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for HeadlessHandle
impl !Send for HeadlessHandle
impl !Sync for HeadlessHandle
impl !UnwindSafe for HeadlessHandle
impl Freeze for HeadlessHandle
impl Unpin for HeadlessHandle
impl UnsafeUnpin for HeadlessHandle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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.