This commit is contained in:
49
src/main.rs
Normal file
49
src/main.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
mod app;
|
||||
mod input;
|
||||
mod theme;
|
||||
mod ui;
|
||||
|
||||
use crossterm::{
|
||||
event, execute,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
use std::io::stdout;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
enable_raw_mode()?;
|
||||
let (width, height) = crossterm::terminal::size()?;
|
||||
if width < 15 || height < 15 {
|
||||
disable_raw_mode()?;
|
||||
println!("Your console is too small.");
|
||||
return Ok(());
|
||||
}
|
||||
let mut stdout = stdout();
|
||||
execute!(stdout, EnterAlternateScreen)?;
|
||||
let backend = CrosstermBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
let mut app = app::App::new();
|
||||
let mut blink_counter = 0;
|
||||
|
||||
loop {
|
||||
let blink = (blink_counter / 3) % 2 == 0;
|
||||
terminal.draw(|f| ui::draw(f, &app, blink))?;
|
||||
blink_counter += 1;
|
||||
let timeout = if app.show_welcome {
|
||||
std::time::Duration::from_millis(70)
|
||||
} else {
|
||||
std::time::Duration::from_millis(60)
|
||||
};
|
||||
if event::poll(timeout)? {
|
||||
let event = event::read()?;
|
||||
if !input::handle_input(&mut app, event) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
disable_raw_mode()?;
|
||||
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user