Struct MockPtyBackend

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

Cloneable mock backend with one shared recording state.

Every clone and every session spawned from the same backend shares spawn configs, writes, resizes, and one global event queue. Session shutdown flags are per spawn, but PtyHandle clones share their session. No automatic output or exit event is generated.

§Panics

Public mock operations panic with "mock pty state" if shared state’s mutex has been poisoned by another thread.

§Examples

use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let backend = MockPtyBackend::default();
backend.spawn(PtySpawnConfig::default()).unwrap().write(b"x").unwrap();
assert_eq!(backend.writes(), vec![b"x".to_vec()]);

Implementations§

Source§

impl MockPtyBackend

Source

pub fn with_spawn_error(self, error: PtyError) -> Self

Configures a cloned error to be returned by every later spawn.

The method consumes and returns this backend value, but mutates state shared with any pre-existing clones. There is no setter to clear the error; create a fresh default backend for successful spawning. Failed configs are not added to Self::spawned_configs.

§Panics

Panics if the shared mock mutex is poisoned.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtyError, PtySpawnConfig};
let backend = MockPtyBackend::default().with_spawn_error(PtyError::Spawn("fixture".into()));
assert_eq!(backend.spawn(PtySpawnConfig::default()).unwrap_err(), PtyError::Spawn("fixture".into()));
assert!(backend.spawned_configs().is_empty());
Source

pub fn push_event(&self, event: PtyEvent)

Appends an event to the global queue without requiring a spawned session.

Events are stored verbatim and drained FIFO by the first session handle that calls drain_events.

§Panics

Panics if the shared mock mutex is poisoned.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtyEvent, PtySpawnConfig};
let backend = MockPtyBackend::default(); backend.push_event(PtyEvent::Output(vec![1, 2]));
let handle = backend.spawn(PtySpawnConfig::default()).unwrap();
assert_eq!(handle.drain_events(), vec![PtyEvent::Output(vec![1, 2])]);
Source

pub fn spawned_configs(&self) -> Vec<PtySpawnConfig>

Clones successful spawn configurations in call order.

§Panics

Panics if the shared mock mutex is poisoned.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let backend = MockPtyBackend::default(); let config = PtySpawnConfig::default();
backend.spawn(config.clone()).unwrap();
assert_eq!(backend.spawned_configs(), vec![config]);
Source

pub fn writes(&self) -> Vec<Vec<u8>>

Clones all successful writes from every shared session.

Empty writes are recorded. Mutating the returned vectors does not change the backend.

§Panics

Panics if the shared mock mutex is poisoned.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let backend = MockPtyBackend::default();
backend.spawn(PtySpawnConfig::default()).unwrap().write(&[]).unwrap();
assert_eq!(backend.writes(), vec![Vec::<u8>::new()]);
Source

pub fn resizes(&self) -> Vec<PtySize>

Clones all successful resize requests from every shared session.

Values are recorded exactly; constructor invariants are not rechecked.

§Panics

Panics if the shared mock mutex is poisoned.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySize, PtySpawnConfig};
let backend = MockPtyBackend::default(); let size = PtySize::new(30, 90, 0, 0);
backend.spawn(PtySpawnConfig::default()).unwrap().resize(size).unwrap();
assert_eq!(backend.resizes(), vec![size]);

Trait Implementations§

Source§

impl Clone for MockPtyBackend

Source§

fn clone(&self) -> MockPtyBackend

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for MockPtyBackend

Source§

fn default() -> MockPtyBackend

Returns the “default value” for a type. Read more
Source§

impl PtyBackend for MockPtyBackend

Source§

fn spawn(&self, config: PtySpawnConfig) -> Result<PtyHandle, PtyError>

Returns the configured error or records config and creates a fresh session.

§Errors

Returns the error installed through Self::with_spawn_error, when one is configured. No session or spawn record is created in that case.

§Panics

Panics if the shared mock-state mutex is poisoned.

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

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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.