1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extern crate crossterm;
use crossterm::event::{poll, read, Event, KeyCode};

extern crate std;
use std::time::Duration;

use crate::events::UserEvent;
use crate::errors::UserError;

pub fn catch_events() -> (UserEvent, UserError) {
  if poll(Duration::from_nanos(1)).unwrap() {
    match read().unwrap() {
      Event::Key(key_event) => {
        if key_event.modifiers.is_empty() {
          match key_event.code {
            KeyCode::Enter => {
              return (UserEvent::Continue, UserError::ResizeCheck)
            },
            _ => (),
          }
        }
      },
      Event::Resize(_, _) => {
        return (UserEvent::GenerationError, UserError::ResizeCheck)
      },
      _ => {},
    }
  }
  (UserEvent::GenerationError, UserError::NoneError)
}