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