use calloop::LoopSignal; use ratatui::{ crossterm::event::{KeyCode, KeyEvent}, layout::Rect, text::Text, }; use ratatui_calloop::{App, ApplicationLoop, Result, Terminal}; fn main() -> Result<()> { let mut app_loop = ApplicationLoop::new()?; let mut app = DemoApp { counter: 0, exit_signal: app_loop.exit_signal(), }; app_loop.run(&mut app) } pub struct DemoApp { counter: i32, exit_signal: LoopSignal, } impl App for DemoApp { fn draw(&self, terminal: &mut Terminal) -> std::io::Result<()> { terminal.draw(|frame| { let text = Text::raw(format!("Counter: {} <↑/↓> ", self.counter)); frame.render_widget(&text, Rect::default()); })?; Ok(()) } fn on_key_event(&mut self, event: KeyEvent) { match event.code { KeyCode::Up => self.counter += 1, KeyCode::Down => self.counter -= 1, KeyCode::Char('q') => self.exit_signal.stop(), _ => {} } } }