modcli/output/input/
confirm.rs1use std::io::{self, Write};
2
3pub fn prompt_confirm(question: &str) -> bool {
5 let mut input = String::new();
6 loop {
7 print!("{} [y/n]: ", question);
8 io::stdout().flush().unwrap();
9
10 input.clear();
11 if let Err(_) = io::stdin().read_line(&mut input) {
12 println!("Error reading input. Try again.");
13 continue;
14 }
15
16 match input.trim().to_lowercase().as_str() {
17 "y" | "yes" => return true,
18 "n" | "no" => return false,
19 _ => {
20 println!("Please enter 'y' or 'n'.");
21 }
22 }
23 }
24}