Skip to main content

max / everycycle

1.5 KB · 47 lines History Blame Raw
1 use std::io;
2 use std::time::Duration;
3
4 use everycycle_tui::audit::{AuditState, render};
5 use ratatui::DefaultTerminal;
6 use ratatui::crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
7
8 fn main() -> io::Result<()> {
9 let mut terminal = ratatui::init();
10 let result = run(&mut terminal);
11 ratatui::restore();
12 result
13 }
14
15 fn run(terminal: &mut DefaultTerminal) -> io::Result<()> {
16 let mut state = AuditState::default();
17 state.refresh();
18
19 loop {
20 terminal.draw(|frame| render(frame, frame.area(), &mut state))?;
21
22 // Block for up to 250 ms so the screen redraws periodically even
23 // without input. The audit screen does not animate today; this
24 // is forward-compat for the live-ops screen that will replace
25 // it as the default landing surface.
26 if !event::poll(Duration::from_millis(250))? {
27 continue;
28 }
29
30 let Event::Key(key) = event::read()? else {
31 continue;
32 };
33 if key.kind != KeyEventKind::Press {
34 continue;
35 }
36
37 match (key.code, key.modifiers) {
38 (KeyCode::Char('q' | 'Q') | KeyCode::Esc, _)
39 | (KeyCode::Char('c' | 'C'), KeyModifiers::CONTROL) => return Ok(()),
40 (KeyCode::Char('r' | 'R'), _) => state.refresh(),
41 (KeyCode::Char('j') | KeyCode::Down, _) => state.select_next(),
42 (KeyCode::Char('k') | KeyCode::Up, _) => state.select_prev(),
43 _ => {}
44 }
45 }
46 }
47