use std::io::{self, IsTerminal, Write}; use crate::reconcile::Action; /// Ask a yes/no question on stdin; anything but "y"/"yes" is a no. pub fn prompt(prompt: &str) -> bool { print!("{prompt}"); let _ = io::stdout().flush(); let mut input = String::new(); let _ = io::stdin().read_line(&mut input); matches!(input.trim().to_ascii_lowercase().as_str(), "y" | "yes") } /// Print an action line, color-coded if stdout is a terminal. pub fn print_action(action: &Action, prune: bool) { let (code, text) = match action { Action::Create(_) => (32, action.describe()), Action::Update { .. } => (33, action.describe()), Action::Delete(_) if !prune => (31, format!("{} (skipped: --no-prune)", action.describe())), Action::Delete(_) => (31, action.describe()), }; println!("{}", paint(code, &text)); } fn paint(code: u8, text: &str) -> String { if io::stdout().is_terminal() { format!("\x1b[{code}m{text}\x1b[0m") } else { text.to_string() } }