module; #include #include #include export module ttwhy.terminal:events; import ttwhy.core; export namespace ttwhy::terminal { //! Represents standard C0 terminal control keys. enum struct control_key : std::uint8_t { enter, escape, tab, backspace, }; //! Represents terminal cursor and keypad navigation keys. enum struct navigation_key : std::uint8_t { up, down, left, right, home, end, delete_key, insert_key, page_up, page_down, }; //! Represents terminal function keys (F1 through F20). enum struct function_key : std::uint8_t { f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, }; //! Represents individual keyboard modifier keys. enum struct modifier : std::uint8_t { none = 0, shift = 1, alt = 2, ctrl = 4, meta = 8, }; //! Represents a bitmask combination of keyboard modifiers. enum struct modifier_set : std::uint8_t { }; //! Combine two keyboard modifiers into a modifier set. //! //! @param lhs The first modifier to combine. //! @param rhs The second modifier to combine. //! @return A modifier set containing both modifiers. constexpr auto operator|(modifier lhs, modifier rhs) -> modifier_set { return static_cast(std::to_underlying(lhs) | std::to_underlying(rhs)); } //! Add a keyboard modifier to an existing modifier set. //! //! @param lhs The existing modifier set. //! @param rhs The modifier to add. //! @return The resulting modifier set. constexpr auto operator|(modifier_set lhs, modifier rhs) -> modifier_set { return static_cast(std::to_underlying(lhs) | std::to_underlying(rhs)); } //! Compute the bitwise intersection of two keyboard modifiers. //! //! @param lhs The first modifier. //! @param rhs The second modifier. //! @return The intersection as a modifier set. constexpr auto operator&(modifier lhs, modifier rhs) -> modifier_set { return static_cast(std::to_underlying(lhs) & std::to_underlying(rhs)); } //! Check for the presence of a keyboard modifier in a modifier set. //! //! @param lhs The modifier set. //! @param rhs The modifier to test. //! @return The intersection as a modifier set. constexpr auto operator&(modifier_set lhs, modifier rhs) -> modifier_set { return static_cast(std::to_underlying(lhs) & std::to_underlying(rhs)); } //! Check whether all specified modifiers are present in a modifier set. //! //! @tparam Modifier The modifier types to check. //! @param mask The modifier set to inspect. //! @param flag The modifier flags that must all be present. //! @return True if all specified flags are present, false otherwise. template... Modifier> constexpr auto has_all(modifier_set mask, Modifier... flag) -> bool { return (true && ... && (mask & flag)); } //! Check whether any of the specified modifiers are present in a modifier set. //! //! @tparam Modifier The modifier types to check. //! @param mask The modifier set to inspect. //! @param flag The modifier flags to test for. //! @return True if at least one of the specified flags is present, false otherwise. template... Modifier> constexpr auto has_any(modifier_set mask, Modifier... flag) -> bool { return (false || ... || (mask & flag)); } //! Represents a printable ASCII or raw character event. struct character_event { char value{}; }; //! Represents a terminal control key event. struct control_event { control_key key{}; }; //! Represents a terminal cursor or keypad navigation event. struct navigation_event { navigation_key key{}; modifier_set modifiers{}; }; //! Represents a Control-key chord event. struct ctrl_chord_event { char key{}; }; //! Represents a terminal function key event. struct function_key_event { function_key key{}; modifier_set modifiers{}; }; //! Variant representing any input event produced by a terminal scanner. using input_event = std::variant; //! Validates that a sink can receive all terminal input event types. //! //! @tparam Sink The sink callable type to validate. template concept event_sink = ttwhy::event_sink && ttwhy::event_sink && ttwhy::event_sink && ttwhy::event_sink && ttwhy::event_sink; } // namespace ttwhy::terminal