pub struct SessionPlayer { /* private fields */ }Expand description
Plays back recorded sessions.
SessionPlayer reads JSONL records, extracts timing information,
and replays events with configurable speed and output modes.
§Example
use ralph_core::{SessionPlayer, PlayerConfig};
use std::io::Cursor;
let jsonl = r#"{"ts":1000,"event":"ux.terminal.write","data":{"bytes":"SGVsbG8=","stdout":true,"offset_ms":0}}
{"ts":1100,"event":"ux.terminal.write","data":{"bytes":"V29ybGQ=","stdout":true,"offset_ms":100}}"#;
let reader = Cursor::new(jsonl);
let player = SessionPlayer::from_reader(reader).unwrap();
assert_eq!(player.record_count(), 2);Implementations§
Source§impl SessionPlayer
impl SessionPlayer
Sourcepub fn from_reader<R: BufRead>(reader: R) -> Result<Self>
pub fn from_reader<R: BufRead>(reader: R) -> Result<Self>
Creates a player from a JSONL reader.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Creates a player from raw JSONL bytes.
Sourcepub fn with_config(self, config: PlayerConfig) -> Self
pub fn with_config(self, config: PlayerConfig) -> Self
Sets the playback configuration.
Sourcepub fn record_count(&self) -> usize
pub fn record_count(&self) -> usize
Returns the number of records.
Sourcepub fn records(&self) -> &[TimestampedRecord]
pub fn records(&self) -> &[TimestampedRecord]
Returns all records.
Sourcepub fn filter_by_event(&self, event_prefix: &str) -> Vec<&TimestampedRecord>
pub fn filter_by_event(&self, event_prefix: &str) -> Vec<&TimestampedRecord>
Returns records filtered by event type.
Sourcepub fn terminal_writes(&self) -> Vec<&TimestampedRecord>
pub fn terminal_writes(&self) -> Vec<&TimestampedRecord>
Returns only UX terminal write events.
Sourcepub fn metadata_events(&self) -> Vec<&TimestampedRecord>
pub fn metadata_events(&self) -> Vec<&TimestampedRecord>
Returns only metadata events.
Sourcepub fn bus_events(&self) -> Vec<&TimestampedRecord>
pub fn bus_events(&self) -> Vec<&TimestampedRecord>
Returns only bus events.
Sourcepub fn replay_terminal<W: Write>(&mut self, writer: &mut W) -> Result<()>
pub fn replay_terminal<W: Write>(&mut self, writer: &mut W) -> Result<()>
Replays all UX terminal events to the given writer.
This is a synchronous replay that respects timing delays adjusted by the speed multiplier. In step mode, it waits for Enter after each event.
Sourcepub fn collect_terminal_output(&self) -> Result<String>
pub fn collect_terminal_output(&self) -> Result<String>
Collects all terminal output as a single string (for snapshot testing).
Sourcepub fn collect_text_output(&self) -> Result<String>
pub fn collect_text_output(&self) -> Result<String>
Collects terminal output with ANSI codes stripped (for text snapshot testing).
Sourcepub fn collect_ansi_escaped(&self) -> Result<String>
pub fn collect_ansi_escaped(&self) -> Result<String>
Collects terminal output with ANSI codes escaped (for ANSI snapshot testing).