command-stream for Rust
Rust implementation of command-stream: a shell command execution library with streaming, events, shell parsing, virtual commands, and built-in command support.
Installation
Library Usage
use CommandResult;
use EchoCommand;
use VirtualCommand;
async
Streaming
StreamingRunner streams output as it arrives and mirrors the JavaScript
stream() async iterator (issue #155):
use ;
async
Parity guarantees with the JavaScript implementation:
- The stream yields a final
OutputChunk::Exit(code)when the process exits. - It never hangs when the process has exited but a grandchild keeps the stdio
pipes open — readers are drained for
exit_pump_grace_ms(default 100ms) and then aborted. - The process can be stopped from inside the loop with
stream.kill()(configured signal) orstream.kill_with(signal)(explicit override); dropping the stream (e.g.break) stops the process too.
Command Line
The crate also builds a command-stream binary:
TUI Capture
capture_terminal runs an interactive program in a real pseudoterminal and
uses vt100 to retain settled terminal states:
use ;
let capture = capture_terminal?;
println!;
# Ok::
The capture contains the raw PTY output, consecutive-deduplicated frames, an
ordered unrolled transcript, and asciicast v2 input/output/resize events. The
artifact directory receives transcript.txt, frames.json, session.cast,
snapshot.svg, and an animated recording.svg; timeout errors retain the
partial capture and those diagnostic files. Use capture_terminal_async from
an async application.
Interactions can wait for literal output with after, regex output with
after_regex, and output quiescence with idle_duration. Named
TerminalKey variants cover arrows, Enter, Tab, Escape, Backspace, Ctrl-C, and
Ctrl-D; use TerminalKey::Raw for any other escape sequence.
Features
- Shell parser for pipelines, command lists, logical operators, and redirection.
- Built-in command implementations for file-system and shell utility commands.
- Async execution with
tokio. - Virtual command abstractions for embedding command behavior in Rust programs.
- Cross-platform tests covering parser, state, events, streams, and built-ins.
Development
Rust release automation lives in scripts/ and is controlled by
.github/workflows/rust.yml from the repository root.