use pish::export_fun;
use std::io::{self, IsTerminal};

fn main() {
    export_fun::maybe_run_defined_function();
    if !io::stdin().is_terminal() {
        println!("need to run in a tty");
        return;
    }

    pish::panic::hook();

    // it is quite annoying when the terminal window closes due to a crash, so let's just catch all panics
    loop {
        let res = std::panic::catch_unwind(pish::event_loop);
        match res {
            Ok(_) => break,
            Err(_) => {
                #[cfg(debug_assertions)]
                unsafe {
                    pish::reload::continue_reload()
                }
            }
        }

        // prevent incredibly fast panic loops
        std::thread::sleep(std::time::Duration::from_secs(1));
    }

    println!("bye");
}
