Skip to main content

FrameRecorder

Struct FrameRecorder 

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

Wraps a backend and records every frame it draws.

Taps Output::draw_layers – the same DrawCell diff stream Terminal::present and every backend already consume – and buffers each call’s changed cells as an owned CapturedFrame, timestamped against when recording started. Works over a Backend, or any subset of Output/Input/Cursor: only Output is tapped, everything else is delegated unchanged, the same shape as InputRecorder.

DrawCell borrows from the source grid, so capture converts to OwnedCell immediately on each draw_layers call rather than deferring to export time, when the borrow would already be gone.

§Known limitation

Buffers the whole session in memory (every frame captured, and every cell in it, lives in the shared FrameRecorderHandle until write_cast exports and take_frames drops it) rather than streaming to disk as frames arrive. Fine for docs/demo-length captures – the ones this crate exists for – but not a fit for an unbounded, long-running recording.

§Examples

use retroglyph_core::backend::{Headless, Output};
use retroglyph_core::color::Style;
use retroglyph_core::grid::Pos;
use retroglyph_core::tile::Tile;
use retroglyph_recorder::FrameRecorder;

let mut recorder = FrameRecorder::new(Headless::new(10, 3));
let tile = Tile::new('x', Style::default());
let cell = retroglyph_core::backend::DrawCell::new(Pos::new(0, 0), &tile);
recorder.draw_layers(std::iter::once(cell)).unwrap();

assert_eq!(recorder.frames().len(), 1);

Implementations§

Source§

impl<B: Output> FrameRecorder<B>

Source

pub fn new(inner: B) -> Self

Wraps inner. Recording starts immediately: the clock CapturedFrame::at is measured against begins ticking here, not on the first draw_layers call.

Source§

impl<B> FrameRecorder<B>

Source

pub fn handle(&self) -> FrameRecorderHandle

A cloneable FrameRecorderHandle onto this recorder’s shared state, for reading captured frames after a driver (e.g. retroglyph_core::app::run_on) has taken this recorder’s Terminal by value and won’t hand it back.

Source

pub fn frames(&self) -> Vec<CapturedFrame>

FrameRecorderHandle::frames on this recorder’s own handle.

Source

pub fn take_frames(&mut self) -> Vec<CapturedFrame>

FrameRecorderHandle::take_frames on this recorder’s own handle.

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 FrameRecorder<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 FrameRecorder<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 FrameRecorder<B>

Source§

type Error = <B as Output>::Error

Error type returned by fallible operations.
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
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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<B> UnwindSafe for FrameRecorder<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.