sim_restaurant/tui/
mod.rs1pub mod app;
4pub mod event;
5pub mod terminal;
6pub mod ui;
7
8use std::io;
9
10use ratatui::Terminal;
11use ratatui::backend::CrosstermBackend;
12
13use crate::recording::RecordedSimulation;
14use crate::tui::event::{AppResult, Event, EventHandler};
15use crate::tui::terminal::Tui;
16
17pub fn run(recording: RecordedSimulation) -> AppResult<()> {
18 let backend = CrosstermBackend::new(io::stdout());
19 let terminal = Terminal::new(backend)?;
20 let events = EventHandler::new(100);
21 let mut tui = Tui::new(terminal);
22 let mut app = app::App::new(recording);
23
24 tui.init()?;
25
26 loop {
27 tui.draw(&mut app)?;
28 match events.next()? {
29 Event::Tick => app.handle_tick(),
30 Event::Key(key) => {
31 if app.handle_key(key) {
32 break;
33 }
34 }
35 Event::Resize(_, _) => {}
36 }
37 }
38
39 tui.exit()?;
40 Ok(())
41}