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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
module;
#include <cstdint>
#include <utility>
#include <variant>
export module ttwhy.terminal:events;
import ttwhy.core;
export namespace ttwhy::terminal
{
enum struct control_key : std::uint8_t
{
enter,
escape,
tab,
backspace,
};
enum struct navigation_key : std::uint8_t
{
up,
down,
left,
right,
home,
end,
delete_key,
insert_key,
page_up,
page_down,
};
enum struct modifier : std::uint8_t
{
none = 0,
shift = 1,
alt = 2,
ctrl = 4,
meta = 8,
};
enum struct modifier_set : std::uint8_t
{
};
constexpr auto operator|(modifier lhs, modifier rhs) -> modifier_set
{
return static_cast<modifier_set>(std::to_underlying(lhs) | std::to_underlying(rhs));
}
constexpr auto operator|(modifier_set lhs, modifier rhs) -> modifier_set
{
return static_cast<modifier_set>(std::to_underlying(lhs) | std::to_underlying(rhs));
}
constexpr auto operator&(modifier lhs, modifier rhs) -> modifier_set
{
return static_cast<modifier_set>(std::to_underlying(lhs) & std::to_underlying(rhs));
}
constexpr auto operator&(modifier_set lhs, modifier rhs) -> modifier_set
{
return static_cast<modifier_set>(std::to_underlying(lhs) & std::to_underlying(rhs));
}
template<std::same_as<modifier>... Modifier>
constexpr auto has_all(modifier_set mask, Modifier... flag) -> bool
{
return (true && ... && (mask & flag));
}
template<std::same_as<modifier>... Modifier>
constexpr auto has_any(modifier_set mask, Modifier... flag) -> bool
{
return (false || ... || (mask & flag));
}
struct character_event
{
char value{};
};
struct control_event
{
control_key key{};
};
struct navigation_event
{
navigation_key key{};
modifier_set modifiers{};
};
struct ctrl_chord_event
{
char key{};
};
using input_event = std::variant<character_event, control_event, navigation_event, ctrl_chord_event>;
template<typename Sink>
concept event_sink = ttwhy::event_sink<Sink, character_event> && ttwhy::event_sink<Sink, control_event> &&
ttwhy::event_sink<Sink, navigation_event>;
} // namespace ttwhy::terminal
|