From 3b1351018d3184caa5b5ca25cc13e5da1fc02229 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 15:41:46 +0100 Subject: 0.4.5: CLI validation, instruction scope, resume context, prompt hygiene - session ids validated; missing flag values and conflicting flags are usage errors - -- terminator; usage goes to stderr - doctor sends a real session header - sessions record their starting cwd and warn when resumed elsewhere - AGENTS.md stops at the git root; no parent-directory injection - typeahead flush, Ctrl-C during prompts, NO_COLOR/TERM=dumb --- src/ui.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/ui.rs') diff --git a/src/ui.rs b/src/ui.rs index 38546ab..d7716a9 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -14,7 +14,13 @@ pub fn stdin_is_tty() -> bool { fn color() -> bool { static COLOR: OnceLock = OnceLock::new(); - *COLOR.get_or_init(stdout_is_tty) + *COLOR.get_or_init(|| { + stdout_is_tty() + && std::env::var_os("NO_COLOR").is_none() + && std::env::var("TERM") + .map(|term| term != "dumb") + .unwrap_or(true) + }) } fn paint(code: &str, text: &str) -> String { @@ -177,10 +183,20 @@ impl Approver { print!("\n{} {} ", question, paint("2", hint)); let _ = std::io::stdout().flush(); + // Typeahead from before the prompt appeared must not answer it: a "y" + // typed during streaming would otherwise approve a command unseen. + unsafe { + libc::tcflush(libc::STDIN_FILENO, libc::TCIFLUSH); + } + let mut line = String::new(); if std::io::stdin().read_line(&mut line).unwrap_or(0) == 0 { return Answer::No; } + // Ctrl-C during the prompt arrives as a signal, not a keystroke. + if crate::signal::CANCEL.load(std::sync::atomic::Ordering::Relaxed) { + return Answer::No; + } match line.trim().to_ascii_lowercase().as_str() { "y" | "yes" => Answer::Yes, "a" | "always" if allow_always => Answer::Always, -- cgit v1.2.3