1mod app;
2mod banner;
3mod ui;
4
5use anyhow::Result;
6use app::App;
7use crossterm::event::{self, Event};
8use std::{path::PathBuf, time::Duration};
9
10#[derive(Debug, Default)]
11pub struct TuiOutcome {
12 pub stdout: Vec<String>,
13}
14
15pub fn run(root: PathBuf) -> Result<TuiOutcome> {
16 let mut app = App::new(root)?;
17 let mut terminal = ratatui::try_init()?;
18
19 let loop_result = run_loop(&mut terminal, &mut app);
20 let restore_result = ratatui::try_restore();
21
22 loop_result?;
23 restore_result?;
24 Ok(TuiOutcome {
25 stdout: app.stdout_after_exit,
26 })
27}
28
29fn run_loop(terminal: &mut ratatui::DefaultTerminal, app: &mut App) -> Result<()> {
30 while !app.should_quit {
31 terminal.draw(|frame| ui::draw(frame, app))?;
32 if event::poll(Duration::from_millis(120))?
33 && let Event::Key(key) = event::read()?
34 {
35 app.handle_key(key)?;
36 }
37 }
38 Ok(())
39}