| Crates.io | replay-rs |
| lib.rs | replay-rs |
| version | 0.0.2 |
| created_at | 2025-06-18 11:55:44.095021+00 |
| updated_at | 2025-06-18 11:55:44.095021+00 |
| description | A Rust library for recording and replaying terminal sessions with timing data |
| homepage | |
| repository | https://github.com/trozz/replay-rs |
| max_upload_size | |
| id | 1716989 |
| size | 222,548 |
A Rust library for recording and replaying terminal sessions with timing data, compatible with the classic Unix script and scriptreplay tools but implemented entirely in Rust with cross-platform support.
script/scriptreplay timing filesAdd this to your Cargo.toml:
[dependencies]
replay-rs = "0.1"
use replay_rs::{Recorder, Player};
use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Record a command
let recorder = Recorder::new("session.log", "session.log.timing")?;
let mut cmd = Command::new("echo");
cmd.arg("Hello, World!");
recorder.record_command(cmd, false)?; // false = binary format, true = text format
// Replay the session
let player = Player::new("session.log.timing", "session.log")?;
player.replay(1.0)?; // 1.0 = normal speed, 2.0 = 2x speed, etc.
Ok(())
}
use replay_rs::{Recorder, Player, clean_for_display};
use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Record with text cleaning (removes problematic ANSI sequences)
let recorder = Recorder::new("clean_session.log", "clean_session.timing")?;
let mut cmd = Command::new("ls");
cmd.arg("--color=always");
recorder.record_command(cmd, true)?; // true = clean text format
// Replay at different speeds
let player = Player::new("clean_session.timing", "clean_session.log")?;
println!("Playing at 2x speed:");
player.replay(2.0)?;
println!("Dumping without timing:");
player.dump()?; // Fast dump without delays
// Manual ANSI cleaning
let raw_output = "?2004h\x1b[32mGreen text\x1b[0m?2004l";
let cleaned = clean_for_display(raw_output);
println!("Cleaned: {}", cleaned); // Outputs: "Green text" (with color preserved)
Ok(())
}
The Recorder struct captures command execution with timing data.
// Create a new recorder
let recorder = Recorder::new("output.log", "timing.log")?;
// Record a command (plain_text: false = raw, true = cleaned)
recorder.record_command(command, plain_text)?;
The Player struct replays recorded sessions.
// Create a player
let player = Player::new("timing.log", "output.log")?;
// Replay with speed control
player.replay(speed_multiplier)?; // 1.0 = normal, 2.0 = 2x, 0.5 = half
// Fast dump without timing
player.dump()?;
// Clean ANSI sequences while preserving colors
let cleaned = clean_for_display(raw_text);
replay-rs uses the same timing file format as the classic Unix scriptreplay command:
delay_in_seconds byte_count
delay_in_seconds byte_count
...
This means you can:
script -tscriptreplay to play files recorded with replay-rs| Feature | replay-rs | asciinema | script/scriptreplay | ttyrec |
|---|---|---|---|---|
| Cross-platform | ✅ | ✅ | ⚠️ (Unix only) | ⚠️ (Unix only) |
| Speed control | ✅ | ✅ | ✅ | ❌ |
| No external deps | ✅ | ❌ | ⚠️ (system tools) | ❌ |
| ANSI cleaning | ✅ | ❌ | ❌ | ❌ |
| Library API | ✅ | ❌ | ❌ | ❌ |
| File compatibility | ✅ | ❌ | ✅ | ❌ |
Run the included examples:
# Simple recording and playback
cargo run --example simple_record_replay
# More examples coming soon!
This library was extracted from the aws-ssm-connector project, where it's used to record and replay AWS SSM sessions with perfect timing and color preservation.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
script and scriptreplay utilities