From b94ebaa4bd05c196ba6daa1d5d8df512d9ebc6d0 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Tue, 17 Jan 2023 17:39:01 -0500 Subject: [PATCH] rm - fix interactive prompts --- src/cmd/rm/mod.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cmd/rm/mod.rs b/src/cmd/rm/mod.rs index e5c45ce..c4688d7 100644 --- a/src/cmd/rm/mod.rs +++ b/src/cmd/rm/mod.rs @@ -266,11 +266,11 @@ impl Action { .and_then(|fd| fd.metadata()) .and_then(|meta| Ok(Filetype::from(meta)))? }; - print!("rm: remove {ft} '{}'? ", &self.path); + eprint!("rm: remove {ft} '{}'? ", &self.path); let mut reply = String::new(); let stdin = io::stdin(); let _read = stdin.read_line(&mut reply); - match reply.as_str() { + match reply.trim_end() { "y" | "Y" | "yes" | "Yes" => Ok(Some(ft)), _ => Ok(None), } @@ -317,14 +317,16 @@ impl AllActions { fn prompt(&self) -> bool { let len = self.items.len(); if len > 3 { - print!("rm: remove {len} arguments? "); - } - let mut reply = String::new(); - let stdin = io::stdin(); - let _read = stdin.read_line(&mut reply); - match reply.as_str() { - "y" | "Y" | "yes" | "Yes" => true, - _ => false, + eprint!("rm: remove {len} arguments? "); + let mut reply = String::new(); + let stdin = io::stdin(); + let _read = stdin.read_line(&mut reply); + match reply.as_str() { + "y" | "Y" | "yes" | "Yes" => true, + _ => false, + } + } else { + true } } }