rusticity_term/event.rs
1use crossterm::event::{self, Event};
2use std::time::Duration;
3
4pub struct EventHandler;
5
6impl Default for EventHandler {
7 fn default() -> Self {
8 Self::new()
9 }
10}
11
12impl EventHandler {
13 pub fn new() -> Self {
14 Self
15 }
16
17 pub fn next(&self) -> anyhow::Result<Option<Event>> {
18 if event::poll(Duration::from_millis(100))? {
19 Ok(Some(event::read()?))
20 } else {
21 Ok(None)
22 }
23 }
24}