terrr 0.1.0

a linux horror game
mod ui;
mod game;

use std::io;
use std::panic;
use anyhow::Result;
use crossterm::{
    terminal::{self, EnterAlternateScreen, LeaveAlternateScreen},
    event::{DisableMouseCapture, EnableMouseCapture},
    execute,
};
use ratatui::Terminal;
use ratatui::backend::CrosstermBackend;

use game::app::App;

fn main() -> Result<()> {
    // Set up panic hook to restore terminal
    let original_hook = panic::take_hook();
    panic::set_hook(Box::new(move |panic_info| {
        // Clean up terminal
        let _ = restore_terminal();
        // Call the original hook
        original_hook(panic_info);
    }));

    // Initialize terminal
    initialize_terminal()?;
    
    // Create app and run it
    let mut app = App::new()?;
    let mut terminal = Terminal::new(CrosstermBackend::new(io::stdout()))?;
    let result = app.run(&mut terminal);
    
    // Restore terminal
    restore_terminal()?;
    
    // Return app result
    result
}

fn initialize_terminal() -> Result<()> {
    terminal::enable_raw_mode()?;
    let mut stdout = io::stdout();
    execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
    Ok(())
}

fn restore_terminal() -> Result<()> {
    terminal::disable_raw_mode()?;
    let mut stdout = io::stdout();
    execute!(stdout, LeaveAlternateScreen, DisableMouseCapture)?;
    Ok(())
}