use andiskaz::{
emergency_restore,
error::Error,
terminal::Terminal,
tstring,
ui::{info::InfoDialog, menu::Menu},
};
use std::{panic, process::exit};
#[tokio::main]
async fn main() {
panic::set_hook(Box::new(|info| {
let _ = emergency_restore();
eprintln!("{}", info);
}));
let result = Terminal::run(term_main).await;
if let Ok(Err(error)) | Err(error) = result {
eprintln!("{}", error);
exit(-1);
}
}
async fn term_main(mut term: Terminal) -> Result<(), Error> {
let mut menu = Menu::new(
tstring!["Choose One"],
vec![
tstring!["This is the right choice."],
tstring!["This is the wrong choice."],
tstring!["I cannot judge this choice."],
],
);
let option = menu.select(&mut term).await?;
InfoDialog::new(
tstring!["Judging what you chose"],
menu.options[option].clone(),
)
.run(&mut term)
.await?;
menu.title = tstring!["Choose One But You Can Cancel"];
let maybe_option = menu.select_with_cancel(&mut term).await?;
let message = match maybe_option {
Some(option) => menu.options[option].clone(),
None => tstring!["You chose nothing? Really?"],
};
InfoDialog::new(tstring!["Judging what you chose"], message)
.run(&mut term)
.await?;
Ok(())
}