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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Subprocess execution that never corrupts the terminal the TUI owns.
//!
//! yolop's renderer owns stdout, and in `--fullscreen` the whole alternate
//! screen — which, unlike the inline viewport, has no scrollback to absorb
//! stray writes. Any child process that *inherits* our stdout/stderr therefore
//! prints straight onto the live frame: the `Preparing worktree …` /
//! `HEAD is now at …` / `From github.com…` corruption of the composer and
//! status bar.
//!
//! The fix is a policy, not a per-call-site patch: **internal subprocesses must
//! keep their output off the terminal.** This module is the single blessed way
//! to spawn them, so the rule is enforceable by "route it through `proc`"
//! instead of remembered (and forgotten) at each `Command`. Prefer these over a
//! bare `Command::status()`/`spawn()`, both of which inherit our stdio.
//!
//! Two shapes cover the internal cases:
//! - [`capture`] — run a one-shot command to completion with its output
//! captured (git, cargo, …); the caller inspects status/stdout/stderr.
//! - [`detach_stdio`] — point a child's three streams at the null device for
//! fire-and-forget launches (opening a browser) we neither read nor want on
//! the frame.
//!
//! Long-running servers that speak a protocol over piped stdin/stdout (the
//! extension host, language servers) are already safe for those two streams;
//! the trap there is *stderr*, which must be piped-and-drained or nulled rather
//! than inherited (see `extensions::manager`).
use io;
use ;
/// Run `cmd` to completion with stdin detached and stdout/stderr **captured**
/// into the returned [`Output`], never inherited from the parent.
///
/// Use for one-shot internal commands whose output must stay off the terminal
/// but whose exit status or captured streams the caller needs (e.g. surfacing
/// stderr in an error message).
/// Point a child's stdin, stdout, and stderr at the null device so nothing it
/// writes can reach the terminal. Returns the same `cmd` for chaining with
/// `.status()`/`.spawn()`.
///
/// Use for fire-and-forget launches (opening a URL in a browser) where we do
/// not consume the child's output.