Read one event fn
@@ -48,24 +48,37 @@ impl InputHandler {
pub(crate) fn fetch_events(&self) -> Result<Vec<Event>, ()> {
let mut inbox: Vec<Event> = Vec::new();
loop {
+ match self.read_event() {
+ Ok(ev_opt) => match ev_opt {
+ Some(ev) => inbox.push(ev),
+ None => break
+ },
+ Err(_) => return Err(())
+ }
+ }
+ Ok(inbox)
+ }
+
+ /// ### read_event
+ ///
+ /// Read event from input listener
+ pub(crate) fn read_event(&self) -> Result<Option<Event>, ()> {
if let Ok(available) = poll(Duration::from_millis(10)) {
match available {
true => {
// Read event
if let Ok(ev) = read() {
- inbox.push(ev);
+ Ok(Some(ev))
} else {
- return Err(());
+ Err(())
}
}
- false => break,
+ false => Ok(None)
}
} else {
- return Err(());
+ Err(())
}
}
- Ok(inbox)
- }
}
#[cfg(test)]
