use andiskaz::{
emergency_restore,
error::Error,
terminal::Terminal,
tstring,
ui::{info::InfoDialog, input::InputDialog},
};
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 dialog = InputDialog::new(
tstring!["Just type your username"],
tstring![],
16,
|ch| ch.is_ascii_alphabetic() || ch.is_ascii_digit() || ch == '_',
);
let username = dialog.select(&mut term).await?;
InfoDialog::new(tstring!["So, this is your name"], username)
.run(&mut term)
.await?;
let mut dialog = InputDialog::new(
tstring!["Type your username again (You can cancel)"],
tstring![],
16,
|ch| ch.is_ascii(),
);
let maybe_uname = dialog.select_with_cancel(&mut term).await?;
let message = maybe_uname.unwrap_or_else(|| tstring!["Why you cancelled?"]);
InfoDialog::new(tstring!["So, this is your name?"], message)
.run(&mut term)
.await?;
Ok(())
}