rm - fix interactive prompts

This commit is contained in:
Nathan Fisher 2023-01-17 17:39:01 -05:00
parent 8a14cfb590
commit b94ebaa4bd

View File

@ -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
}
}
}