virtual-tty
A pure Rust virtual terminal (TTY) emulator for testing terminal applications without requiring a real terminal or PTY.
Features
- No Dependencies: Pure Rust implementation with zero runtime dependencies
- ANSI Support: Handles common terminal escape sequences (cursor movement, colors, clearing)
- Thread Safe: Safe concurrent access to terminal buffer
- Deterministic: Consistent behavior for reliable testing
- Platform Independent: Works on all platforms without Unix-specific APIs
Usage
use VirtualTty;
// Create a virtual terminal
let mut tty = new;
// Write to stdout
tty.stdout_write;
// Write ANSI escape sequences
tty.stdout_write;
// Get terminal snapshot
let snapshot = tty.get_snapshot;
assert!;
Testing CLI Applications
use VirtualTty;
ANSI Escape Sequences
Supported sequences include:
- Cursor movement:
ESC[A(up),ESC[B(down),ESC[C(right),ESC[D(left) - Cursor positioning:
ESC[H,ESC[{row};{col}H - Screen clearing:
ESC[J(clear screen),ESC[K(clear line) - Colors and styles:
ESC[31m(red),ESC[1m(bold), etc.
License
MIT