Skip to main content

InputRecorder

Struct InputRecorder 

Source
pub struct InputRecorder<B> { /* private fields */ }
Expand description

Wraps a backend and records every event it sees.

Works over a Backend, or any subset of Output/Input/Cursor: taps Input::poll_event to capture, while delegating everything else unchanged.

Recording starts immediately on construction; use handle (or the convenience start/pause/stop/ save methods on this type, which forward to it) to control capture and save it to a .rgrec file.

§Examples

use retroglyph_core::backend::{Headless, Input};
use retroglyph_core::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use retroglyph_recorder::InputRecorder;

let mut recorder = InputRecorder::new(Headless::new(10, 3));
recorder.push_event(Event::Key(KeyEvent::new(KeyCode::Char('a'), KeyModifiers::NONE)));
let event = recorder.poll_event(std::time::Duration::ZERO);
assert!(event.is_some());

let recording = recorder.stop();
assert_eq!(recording.len(), 1);

Implementations§

Source§

impl<B: Output> InputRecorder<B>

Source

pub fn new(inner: B) -> Self

Wraps inner, sizing the recording to inner’s current Output::size.

Source§

impl<B> InputRecorder<B>

Source

pub fn handle(&self) -> RecorderHandle

A cloneable RecorderHandle onto this recorder’s shared state, for reaching in from another call stack (see RecorderHandle’s own docs).

Source

pub fn start(&self)

RecorderHandle::start on this recorder’s own handle.

Source

pub fn pause(&self)

RecorderHandle::pause on this recorder’s own handle.

Source

pub fn snapshot(&self) -> InputRecording

RecorderHandle::snapshot on this recorder’s own handle.

Source

pub fn stop(&self) -> InputRecording

RecorderHandle::stop on this recorder’s own handle.

Source

pub fn save(&self, path: impl AsRef<Path>) -> Result<()>

RecorderHandle::save on this recorder’s own handle.

§Errors

Returns an error if path cannot be created or written to.

Source

pub const fn inner(&self) -> &B

The wrapped backend, for anything not exposed through the decorator itself.

Source

pub const fn inner_mut(&mut self) -> &mut B

The wrapped backend, mutably.

Trait Implementations§

Source§

impl<B: Cursor> Cursor for InputRecorder<B>

Source§

fn set_cursor_visible(&mut self, visible: bool)

Show or hide the cursor.
Source§

fn set_cursor_position(&mut self, position: Pos)

Move the cursor to a position.
Source§

fn set_cursor_style(&mut self, style: CursorStyle)

Set the cursor’s shape (and blink behavior). Read more
Source§

impl<B: Input> Input for InputRecorder<B>

Source§

fn poll_event(&mut self, timeout: Duration) -> Option<Event>

Poll for an input event, waiting up to timeout.
Source§

fn push_event(&mut self, event: Event)

Push an event into the backend’s event buffer. Read more
Source§

impl<B: Output> Output for InputRecorder<B>

Source§

type Error = <B as Output>::Error

Error type returned by fallible operations.
Source§

fn draw<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
where I: Iterator<Item = DrawCell<'a>>,

Draw changed cells to the output surface, layer 0 only. Read more
Source§

fn draw_layers<'a, I>(&mut self, content: I) -> Result<(), Self::Error>
where I: Iterator<Item = DrawCell<'a>>,

Draw changed cells across all layers. Read more
Source§

fn compositing(&self) -> Compositing

How this backend wants layers handed to draw_layers. Read more
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Flush buffered output to the display. Read more
Source§

fn size(&self) -> Size

Return current display dimensions.
Source§

fn clear(&mut self) -> Result<(), Self::Error>

Clear the entire display. Read more
Source§

fn resize(&mut self, size: Size)

Notify the backend of a resize to size, updating what size reports. Read more

Auto Trait Implementations§

§

impl<B> Freeze for InputRecorder<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for InputRecorder<B>
where B: RefUnwindSafe,

§

impl<B> Send for InputRecorder<B>
where B: Send,

§

impl<B> Sync for InputRecorder<B>
where B: Sync,

§

impl<B> Unpin for InputRecorder<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for InputRecorder<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for InputRecorder<B>
where B: UnwindSafe,

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> Backend for T
where T: Output + Input + Cursor,

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
§

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