Completed events unit tests
This commit is contained in:
@@ -14,7 +14,6 @@ pub enum InputEvent<T> {
|
||||
}
|
||||
|
||||
pub struct Events {
|
||||
_tx: Sender<InputEvent<Key>>,
|
||||
rx: Receiver<InputEvent<Key>>,
|
||||
}
|
||||
|
||||
@@ -23,7 +22,6 @@ impl Events {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let tick_rate: Duration = Duration::from_millis(250);
|
||||
|
||||
let event_tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
let mut last_tick = Instant::now();
|
||||
loop {
|
||||
@@ -33,18 +31,18 @@ impl Events {
|
||||
if event::poll(timeout).unwrap() {
|
||||
if let CrosstermEvent::Key(key_event) = event::read().unwrap() {
|
||||
let key = Key::from(key_event);
|
||||
event_tx.send(InputEvent::KeyEvent(key)).unwrap();
|
||||
tx.send(InputEvent::KeyEvent(key)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if last_tick.elapsed() >= tick_rate {
|
||||
event_tx.send(InputEvent::Tick).unwrap();
|
||||
tx.send(InputEvent::Tick).unwrap();
|
||||
last_tick = Instant::now();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Events { _tx: tx, rx }
|
||||
Events { rx }
|
||||
}
|
||||
|
||||
pub fn next(&self) -> Result<InputEvent<Key>, mpsc::RecvError> {
|
||||
|
||||
Reference in New Issue
Block a user