replay-rs
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.
Features
- 🎥 Record terminal sessions: Capture command output with precise timing data
- 🎬 Replay with speed control: Play back sessions at different speeds (like asciinema)
- 🎨 ANSI sequence handling: Clean up problematic control sequences while preserving colors
- 🖥️ Cross-platform: Works on macOS, Linux, and other Unix-like systems
- ⚡ Zero external dependencies: Built-in implementation, no need for external tools
- 📄 Multiple formats: Support for both raw binary and cleaned text output
- 🔧 Compatible: Works with existing
script
/scriptreplay
timing files
Quick Start
Add this to your Cargo.toml
:
[]
= "0.1"
Basic Usage
use ;
use Command;
Advanced Usage
use ;
use Command;
API Documentation
Recorder
The Recorder
struct captures command execution with timing data.
// Create a new recorder
let recorder = new?;
// Record a command (plain_text: false = raw, true = cleaned)
recorder.record_command?;
Player
The Player
struct replays recorded sessions.
// Create a player
let player = new?;
// Replay with speed control
player.replay?; // 1.0 = normal, 2.0 = 2x, 0.5 = half
// Fast dump without timing
player.dump?;
Utility Functions
// Clean ANSI sequences while preserving colors
let cleaned = clean_for_display;
File Format Compatibility
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:
- Use replay-rs to play files recorded with
script -t
- Use
scriptreplay
to play files recorded with replay-rs - Mix and match tools as needed
Use Cases
- 📚 Documentation: Record setup procedures and tutorials
- 🎓 Training: Create step-by-step command demonstrations
- 🐛 Debugging: Capture and share terminal sessions for troubleshooting
- 📊 Automation: Record command outputs for later analysis
- 🔍 Auditing: Maintain logs of terminal activities
- 🎮 Demos: Create smooth terminal recordings for presentations
Comparison with Other Tools
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 | ✅ | ❌ | ✅ | ❌ |
Examples
Run the included examples:
# Simple recording and playback
# More examples coming soon!
Real-World Usage
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.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by the classic Unix
script
andscriptreplay
utilities - Built with modern Rust for safety and cross-platform compatibility
- Thanks to the asciinema project for pioneering terminal session recording