aboutsummaryrefslogtreecommitdiff
path: root/ttwhy/terminal/events.cppm
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2026-09-22 22:47:33 +0200
committerFelix Morgner <felix.morgner@gmail.com>2026-09-22 22:47:33 +0200
commitd05b9343f69a0841043963088e0003368e205bd9 (patch)
tree8cde07ff86d27cbc808a0a149b89d0024b4a586c /ttwhy/terminal/events.cppm
parent22f6534081acfabdab4956d337604a21e7da5b64 (diff)
downloadttwhy-d05b9343f69a0841043963088e0003368e205bd9.tar.xz
ttwhy-d05b9343f69a0841043963088e0003368e205bd9.zip
lib: restructure into vertical slicesHEADmaster
Diffstat (limited to 'ttwhy/terminal/events.cppm')
-rw-r--r--ttwhy/terminal/events.cppm107
1 files changed, 107 insertions, 0 deletions
diff --git a/ttwhy/terminal/events.cppm b/ttwhy/terminal/events.cppm
new file mode 100644
index 0000000..93b2326
--- /dev/null
+++ b/ttwhy/terminal/events.cppm
@@ -0,0 +1,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