Guide API
Skip to main content

HeadlessHandle

Struct HeadlessHandle 

Source
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

Source

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!.

Source

pub fn push_event(&self, ev: Event)

Queue an input event to be returned by the next poll_event.

Source

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.

Source

pub fn push_paste(&self, text: impl Into<String>)

Queue a bracketed-paste event. Equivalent to the terminal delivering an EnableBracketedPaste-wrapped paste sequence.

Source

pub fn buffer(&self) -> Ref<'_, Buffer>

Borrow the current screen buffer (for assertions beyond the snapshot).

Source

pub fn cursor(&self) -> Option<(u16, u16)>

The current cursor position: Some((x, y)) when visible, None when hidden.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> HeadlessHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.