pnc 0.2.0

A fast, fully offline, terminal-only reverse Polish notation (RPN) calculator
use crossterm::cursor::{Hide, Show};
use crossterm::terminal::{
    EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode,
};
use std::io::{self, stdout};
use std::panic;
use tracing::info;

pub fn flush_log() {}

pub fn install_panic_hook() {
    let original = panic::take_hook();
    panic::set_hook(Box::new(move |info| {
        tracing::error!(target: "pnc::panic", payload = %info);
        flush_log();
        let _ = restore();
        original(info);
    }));
}

pub fn init() -> io::Result<()> {
    enable_raw_mode()?;
    crossterm::execute!(stdout(), EnterAlternateScreen, Hide)?;
    info!(target: "pnc::terminal", "terminal initialized");
    Ok(())
}

pub fn restore() -> io::Result<()> {
    disable_raw_mode()?;
    crossterm::execute!(stdout(), Show, LeaveAlternateScreen)?;
    info!(target: "pnc::terminal", "terminal restored");
    Ok(())
}