summaryrefslogtreecommitdiff
path: root/input.ha
diff options
context:
space:
mode:
Diffstat (limited to 'input.ha')
-rw-r--r--input.ha45
1 files changed, 45 insertions, 0 deletions
diff --git a/input.ha b/input.ha
new file mode 100644
index 0000000..dd3f34e
--- /dev/null
+++ b/input.ha
@@ -0,0 +1,45 @@
+use vt;
+use io;
+
+type move = enum {
+ UP,
+ DOWN,
+ LEFT,
+ RIGHT,
+};
+type wait = void;
+type quit = void;
+
+type unknown = !void;
+type input = (move | wait | quit | unknown);
+
+
+fn get_input(term: *vt::term) (input | io::EOF | vt::error) = {
+ const key = match (vt::getevent(term)?) {
+ case io::EOF => return io::EOF;
+ case let e: vt::event => yield e.value;
+ };
+ match (key) {
+ case let r: rune => switch (r) {
+ case 'h' => return move::LEFT;
+ case 'l' => return move::RIGHT;
+ case 'j' => return move::DOWN;
+ case 'k' => return move::UP;
+ case '.' => return wait;
+ case 'q' => return quit;
+ case => return unknown;
+ };
+ case let s: vt::specialkey => switch (s) {
+ case vt::specialkey::UP => return move::UP;
+ case vt::specialkey::DOWN => return move::DOWN;
+ case vt::specialkey::LEFT => return move::LEFT;
+ case vt::specialkey::RIGHT => return move::RIGHT;
+ case => return unknown;
+ };
+ case => return unknown;
+ };
+};
+
+
+
+