From 6c1da2802d626632bdcf370ba013da1c9adc2260 Mon Sep 17 00:00:00 2001 From: Saadanjum0 <160885369+Saadanjum0@users.noreply.github.com> Date: Thu, 1 Oct 2026 16:19:39 +0500 Subject: [PATCH] Refuse watch mode when stdout is not a terminal Previously 'procs -w | cat' streamed ANSI screen frames into the pipe forever. Now it exits with an error, like top and watch do. Plain output piping is unchanged. Refs #982. --- src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.rs b/src/main.rs index 9a51b686d..38e29b821 100644 --- a/src/main.rs +++ b/src/main.rs @@ -204,7 +204,15 @@ fn run_list() { } } +fn check_watch_tty(is_tty: bool) -> Result<(), Error> { + if !is_tty { + anyhow::bail!("--watch requires a terminal, but stdout is not a TTY"); + } + Ok(()) +} + fn run_watch(opt: &mut Opt, config: &Config, interval: u64) -> Result<(), Error> { + check_watch_tty(Term::stdout().is_term())?; Watcher::start(opt, config, interval) } @@ -310,6 +318,12 @@ mod tests { assert!(ret.is_ok()); } + #[test] + fn test_watch_requires_tty() { + assert!(check_watch_tty(false).is_err()); + assert!(check_watch_tty(true).is_ok()); + } + #[test] fn test_run_gen_config() { let ret = run_gen_config();