Skip to main content

dejavu/exec/
interactive.rs

1//! Interactive / watch / TTY detection (spec §21.3).
2
3use std::io::IsTerminal;
4
5pub fn stdin_is_tty() -> bool {
6    std::io::stdin().is_terminal()
7}
8
9/// Watch-mode flags that keep a process running (→ passthrough). Note `-w` is
10/// deliberately excluded: for `grep`/`find` it means "word"/"writable", not watch.
11pub fn has_watch_flag(args: &[String]) -> bool {
12    args.iter()
13        .any(|a| matches!(a.as_str(), "--watch" | "--watchAll" | "--watch=true"))
14}
15
16/// `(shim, subcommand)` pairs that inherently prompt / hold the terminal.
17pub fn is_known_interactive(shim: &str, subcommand: Option<&str>) -> bool {
18    matches!(
19        (shim, subcommand),
20        ("npm", Some("init"))
21            | ("npm", Some("login"))
22            | ("npm", Some("adduser"))
23            | ("yarn", Some("login"))
24            | ("docker", Some("exec"))
25            | ("docker", Some("attach"))
26    )
27}