use std::io;

use anyhow::Result;
use clap::Parser;
use crossterm::terminal::{self, LeaveAlternateScreen};
use crossterm::ExecutableCommand;
use donion::Cli;

#[tokio::main]
async fn main() -> Result<()> {
    let default_hook = std::panic::take_hook();
    std::panic::set_hook(Box::new(move |info| {
        let _ = terminal::disable_raw_mode();
        let _ = io::stdout().execute(LeaveAlternateScreen);
        default_hook(info);
    }));

    let args = Cli::parse();
    donion::run(args).await
}
