1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Streaming subprocess control: spawn a child, read its **stdout** and
//! **stderr** line-by-line, write to its **stdin**, and cancel it
//! (SIGTERM → SIGKILL on unix, `TerminateProcess` elsewhere). No console
//! window is flashed on Windows.
//!
//! It knows no CLI's output format and no agent's protocol — it moves lines.
//!
//! A child gets **pipes, never a terminal**, so `isatty` is false for it. That
//! is usually what you want — no colour codes, no progress bars — but a CLI
//! built around interactive prompts will refuse or hang, so run those in
//! whatever non-interactive mode they offer. [`needs_terminal`] recognises the
//! complaint when one slips through.
//!
//! ```no_run
//! use cli_stream::{Command, Event};
//!
//! # fn main() -> Result<(), cli_stream::StreamError> {
//! // stdout and stderr are always streamed.
//! let (handle, events) = Command::new("some-cli").args(["--verbose"]).start()?;
//! for event in events {
//! match event {
//! Event::Stdout { line, .. } => println!("out: {line}"),
//! Event::Stderr { line, .. } => eprintln!("err: {line}"),
//! _ => {}
//! }
//! }
//! # let _ = handle;
//! # Ok(())
//! # }
//! ```
//!
//! Stdin is opt-in, because a child that inherits a terminal's stdin can block
//! forever waiting for input nobody is typing. Ask for it and answer the child
//! as it asks — the handle is yours for the whole run:
//!
//! ```no_run
//! use cli_stream::{Command, Event, Stdin};
//!
//! # fn main() -> Result<(), cli_stream::StreamError> {
//! let (handle, events) = Command::new("some-cli").stdin(Stdin::Piped).start()?;
//! for event in events {
//! if let Event::Stdout { line, .. } = event {
//! if line.contains("Password:") {
//! handle.write_line("hunter2")?;
//! }
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! [`Command::stream`] takes a callback instead, for a caller forwarding onto a
//! sink rather than looping.
//!
//! [`InstallEvent`] is the sibling shape for streamed install/login output.
//!
//! A deliberate *leaf*: it depends on nothing of ours, so anything driving a
//! CLI can use it. Finding a CLI a user installed — resolving a bare name,
//! locating the `node` it was installed beside — is a different question, and
//! lives with the caller that needs it (`agent_harness::node_cli`).
pub use StreamError;
pub use InstallEvent;
pub use ;