From d413e6b54d0c505a529ca6a9a90ddf73c07a8c42 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 13 Nov 2023 01:11:53 +0000 Subject: add entities, sort of --- input.ha | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 input.ha (limited to 'input.ha') 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; + }; +}; + + + + -- cgit v1.2.3