Change to the Termion Key enum

This commit is contained in:
Brooks J Rady 2021-01-07 10:49:43 +00:00
parent b39ec4c0b7
commit 25356a592c
3 changed files with 25 additions and 42 deletions

View file

@ -1,37 +0,0 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize)]
pub struct KeyEvent {
pub code: KeyCode,
pub modifiers: KeyModifiers,
}
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize)]
pub struct KeyModifiers {
pub bits: u8,
//pub shift: bool,
//pub ctrl: bool,
//pub alt: bool,
}
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize)]
pub enum KeyCode {
Backspace,
Enter,
Left,
Right,
Up,
Down,
Home,
End,
PageUp,
PageDown,
Tab,
BackTab,
Delete,
Insert,
F(u8),
Char(char),
Null,
Esc,
}

View file

@ -1,13 +1,11 @@
mod keys;
mod shim;
pub use keys::*;
pub use shim::*;
pub trait MosaicTile {
fn init(&mut self);
fn draw(&mut self, rows: usize, cols: usize);
fn handle_key(&mut self, key: KeyEvent);
fn handle_key(&mut self, key: Key);
}
#[macro_export]

View file

@ -1,7 +1,29 @@
use crate::keys::KeyEvent;
use serde::{Deserialize, Serialize};
use std::{io, path::Path};
pub fn get_key() -> KeyEvent {
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Key {
Backspace,
Left,
Right,
Up,
Down,
Home,
End,
PageUp,
PageDown,
BackTab,
Delete,
Insert,
F(u8),
Char(char),
Alt(char),
Ctrl(char),
Null,
Esc,
}
pub fn get_key() -> Key {
let mut json = String::new();
io::stdin().read_line(&mut json).unwrap();
serde_json::from_str(&json).unwrap()