| Crates.io | virtual-tty |
| lib.rs | virtual-tty |
| version | 0.1.0 |
| created_at | 2025-07-09 21:40:26.216384+00 |
| updated_at | 2025-07-09 21:40:26.216384+00 |
| description | Core virtual TTY implementation for testing terminal applications |
| homepage | |
| repository | https://github.com/xavescor/virtual-tty |
| max_upload_size | |
| id | 1745541 |
| size | 112,586 |
A pure Rust virtual terminal (TTY) emulator for testing terminal applications without requiring a real terminal or PTY.
use virtual_tty::VirtualTty;
// Create a virtual terminal
let mut tty = VirtualTty::new(80, 24);
// Write to stdout
tty.stdout_write("Hello, world!\n");
// Write ANSI escape sequences
tty.stdout_write("\x1b[31mRed text\x1b[0m\n");
// Get terminal snapshot
let snapshot = tty.get_snapshot();
assert!(snapshot.contains("Red text"));
use virtual_tty::VirtualTty;
#[test]
fn test_my_cli_app() {
let mut tty = VirtualTty::new(80, 24);
// Run your CLI app with the virtual terminal
my_app.run(&mut tty);
// Verify the output
let output = tty.get_snapshot();
assert!(output.contains("Expected output"));
}
Supported sequences include:
ESC[A (up), ESC[B (down), ESC[C (right), ESC[D (left)ESC[H, ESC[{row};{col}HESC[J (clear screen), ESC[K (clear line)ESC[31m (red), ESC[1m (bold), etc.MIT