summaryrefslogtreecommitdiff
path: root/input.ha
blob: dd3f34ec301979d0c0c9bd0d68e220864f08c562 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
	};
};