This commit is contained in:
Yurii Rashkovskii 2023-11-19 21:39:10 -07:00 committed by GitHub
commit 0aa411f92a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -34,6 +34,7 @@ struct Event {
static Event Special(std::string);
static Event Mouse(std::string, Mouse mouse);
static Event CursorReporting(std::string, int x, int y);
static Event CustomTagged(int tag);
// --- Arrow ---
static const Event ArrowLeft;
@ -78,9 +79,14 @@ struct Event {
const std::string& input() const { return input_; }
bool operator==(const Event& other) const { return input_ == other.input_; }
bool operator==(const Event& other) const {
return type_ == Type::Custom && other.type_ == Type::Custom ? data_.custom_tag == other.data_.custom_tag : input_ == other.input_;
}
bool operator!=(const Event& other) const { return !operator==(other); }
int is_custom(int tag) const { return type_ == Type::Custom && data_.custom_tag == tag; }
int is_custom() const { return type_ == Type::Custom; }
//--- State section ----------------------------------------------------------
ScreenInteractive* screen_ = nullptr;
@ -92,6 +98,7 @@ struct Event {
Character,
Mouse,
CursorReporting,
Custom,
};
Type type_ = Type::Unknown;
@ -103,6 +110,7 @@ struct Event {
union {
struct Mouse mouse;
struct Cursor cursor;
int custom_tag;
} data_ = {};
std::string input_;

View File

@ -69,6 +69,15 @@ Event Event::CursorReporting(std::string input, int x, int y) {
return event;
}
// static
Event Event::CustomTagged(int tag) {
Event event;
event.type_ = Type::Custom;
event.data_.custom_tag = tag;
return event;
}
// --- Arrow ---
const Event Event::ArrowLeft = Event::Special("\x1B[D"); // NOLINT
const Event Event::ArrowRight = Event::Special("\x1B[C"); // NOLINT