pub struct ReplayHost { /* private fields */ }Expand description
A host that plays bytes back instead of running anything: for tests,
demos and recordings. What it plays is given up front
(output, exit) or later through a
ReplayHandle, which also sees what the pane sent it.
use rich_embed::{ExitStatus, ReplayHost};
let host = ReplayHost::new().output("hello\r\n").exit(ExitStatus::with_code(0));
let handle = host.handle();
assert!(handle.written().is_empty());Implementations§
Source§impl ReplayHost
impl ReplayHost
pub fn new() -> ReplayHost
Sourcepub fn output(self, bytes: impl AsRef<[u8]>) -> ReplayHost
pub fn output(self, bytes: impl AsRef<[u8]>) -> ReplayHost
Play bytes as the program’s output once it starts.
Sourcepub fn exit(self, status: ExitStatus) -> ReplayHost
pub fn exit(self, status: ExitStatus) -> ReplayHost
Exit with status once the output has played.
Sourcepub fn handle(&self) -> ReplayHandle
pub fn handle(&self) -> ReplayHandle
A handle to feed more output, end the program, and see what was sent to it. It may go to another thread.
Trait Implementations§
Source§impl Default for ReplayHost
impl Default for ReplayHost
Source§impl PtyHost for ReplayHost
impl PtyHost for ReplayHost
Source§fn start(&mut self, columns: u16, rows: u16) -> Result<()>
fn start(&mut self, columns: u16, rows: u16) -> Result<()>
Start the program on a screen
columns x rows cells. Called once,
when the pane is first laid out.Source§fn write(&mut self, bytes: &[u8]) -> Result<()>
fn write(&mut self, bytes: &[u8]) -> Result<()>
Send
bytes to the program, as if typed. A host may refuse with
io::ErrorKind::WouldBlock while the program’s input is full
(it is not reading it): nothing was sent, and the same bytes can be
sent again later.Source§fn resize(&mut self, columns: u16, rows: u16) -> Result<()>
fn resize(&mut self, columns: u16, rows: u16) -> Result<()>
The pane is now
columns x rows cells.Source§fn read(&mut self) -> Vec<u8> ⓘ
fn read(&mut self) -> Vec<u8> ⓘ
The output that arrived since the last call; empty when there is
none. Never blocks.
Source§fn set_notify(&mut self, notify: Notify)
fn set_notify(&mut self, notify: Notify)
Call
notify whenever output arrives or the program exits. Given
once, before or after start; a host with something
already waiting calls it at once.Source§fn exit_status(&mut self) -> Option<ExitStatus>
fn exit_status(&mut self) -> Option<ExitStatus>
How the program ended, once it has, and once the output it wrote
before that has been read.
Auto Trait Implementations§
impl Freeze for ReplayHost
impl RefUnwindSafe for ReplayHost
impl Send for ReplayHost
impl Sync for ReplayHost
impl Unpin for ReplayHost
impl UnsafeUnpin for ReplayHost
impl UnwindSafe for ReplayHost
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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn 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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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.Source§fn as_any(&self) -> &(dyn Any + 'static)
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.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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.