thedes_tui_core/input/device/
native.rs1use std::time::Duration;
2
3use crate::event::{InternalEvent, native_ext::FromCrossterm};
4
5use super::{Error, InputDevice};
6
7pub fn open() -> Box<dyn InputDevice> {
8 Box::new(NativeInputDevice)
9}
10
11#[derive(Debug)]
12struct NativeInputDevice;
13
14impl InputDevice for NativeInputDevice {
15 fn blocking_read(
16 &mut self,
17 timeout: Duration,
18 ) -> Result<Option<InternalEvent>, Error> {
19 if crossterm::event::poll(timeout)? {
20 let crossterm_event = crossterm::event::read()?;
21 Ok(InternalEvent::from_crossterm(crossterm_event))
22 } else {
23 Ok(None)
24 }
25 }
26}