about summary refs log tree commit diff
path: root/src/types/command.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types/command.rs')
-rw-r--r--src/types/command.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/types/command.rs b/src/types/command.rs
new file mode 100644
index 000000000000..86f83a12c181
--- /dev/null
+++ b/src/types/command.rs
@@ -0,0 +1,23 @@
+use super::Direction;
+use super::Direction::*;
+use termion::event::Key;
+use termion::event::Key::Char;
+
+pub enum Command {
+    Quit,
+    Move(Direction),
+}
+
+impl Command {
+    pub fn from_key(k: Key) -> Option<Command> {
+        use Command::*;
+        match k {
+            Char('q') => Some(Quit),
+            Char('h') | Char('a') | Key::Left => Some(Move(Left)),
+            Char('k') | Char('w') | Key::Up => Some(Move(Up)),
+            Char('j') | Char('s') | Key::Down => Some(Move(Down)),
+            Char('l') | Char('d') | Key::Right => Some(Move(Right)),
+            _ => None,
+        }
+    }
+}