mod app;
mod file;
mod preview;

use app::{App, Signal};
use std::io::{stdin, stdout, Write};
use termion::{
    clear::All,
    cursor::{Goto, Show},
    input::TermRead,
    raw::IntoRawMode,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut app = App::new()?;

    let stdin = stdin();
    let mut stdout = stdout().into_raw_mode()?;

    app.draw(&mut stdout)?;
    for key in stdin.keys() {
        use Signal::*;
        match app.handle_key(key?)? {
            Exit => break,
            Redraw => app.draw(&mut stdout)?,
            Nothing => (),
        }
    }

    write!(stdout, "{}{}{}", All, Goto(1, 1), Show)?;

    Ok(())
}
