huellas/src/tui/mod.rs

43 lines
1,017 B
Rust
Raw Normal View History

2025-06-13 18:38:31 -04:00
//! TUI
pub mod keys;
pub mod state;
pub mod terminal;
pub mod ui;
use anyhow::Result;
use state::State;
use terminal::Event;
use crate::places::db_repository::DbPlacesRepository;
/// Fires up the UI
pub async fn tui(places_repository: DbPlacesRepository) -> Result<()> {
let (_, terminal_height) = crossterm::terminal::size()?;
let mut state = State::new(places_repository, terminal_height);
let mut tui = terminal::Tui::new()?;
let result = loop {
match tui.next().await? {
Event::Key(key_event) => keys::handle_key(&mut state, key_event).await,
Event::Render => {
tui.draw(|frame| ui::ui_draw(&mut state, frame))?;
}
Event::Tick => {
state.fetch_places().await;
}
Event::Resize(_, h) => state.height = h,
Event::Quit => state.quit = true,
_ => {}
}
if state.quit {
break Ok(());
}
};
tui.stop()?;
result
}