use std::io::{self, Write};
use color_print::cformat;
use worktrunk::styling::PROMPT_SYMBOL;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PromptResponse {
Accepted,
Declined,
}
pub fn prompt_yes_no_preview(
prompt_text: &str,
show_preview: impl Fn(),
) -> io::Result<PromptResponse> {
worktrunk::styling::eprintln!();
loop {
eprint!(
"{}",
cformat!("{PROMPT_SYMBOL} {prompt_text} <bold>[y/N/?]</> ")
);
io::stderr().flush()?;
let mut input = String::new();
io::stdin().read_line(&mut input)?;
let response = input.trim().to_lowercase();
match response.as_str() {
"y" | "yes" => {
return Ok(PromptResponse::Accepted);
}
"?" => {
show_preview();
}
_ => {
return Ok(PromptResponse::Declined);
}
}
}
}