-
Notifications
You must be signed in to change notification settings - Fork 3
/
keys.h
53 lines (41 loc) · 1.28 KB
/
keys.h
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
46
47
48
49
50
51
52
53
#ifndef SNAKE_KEYS_H_INCLUDED
#define SNAKE_KEYS_H_INCLUDED
#include <iosfwd>
namespace keys {
void line_buffering_off();
void line_buffering_on();
struct key {
enum type : char {
none,
unknown,
printable,
escape = 27,
up_arrow = 65,
down_arrow = 66,
right_arrow = 67,
left_arrow = 68,
open_square_bracket = 91
};
type key_type;
char character;
key( type key_type ) : key_type( key_type ), character( 0 ) {}
key( char character ) : key_type( printable ), character( character ) {}
explicit operator bool() const { return key_type != none; }
auto operator == ( char c ) const -> bool {
return character == c;
}
auto operator == ( type t ) const -> bool {
return key_type == t;
}
auto operator != ( char c ) const -> bool {
return character != c;
}
auto operator != ( type t ) const -> bool {
return key_type != t;
}
friend std::ostream& operator <<( std::ostream& os, key key );
};
auto keys_available() -> bool;
auto get_key() -> key;
} // namespace keys
#endif //SNAKE_KEYS_H_INCLUDED