FTXUI/include/ftxui/component/event.hpp

60 lines
1.5 KiB
C++
Raw Normal View History

#ifndef FTXUI_COMPONENT_EVENT_HPP
#define FTXUI_COMPONENT_EVENT_HPP
2018-10-19 04:58:38 +08:00
#include <array>
#include <functional>
2019-06-30 16:11:37 +08:00
#include <string>
#include <vector>
2018-10-19 04:58:38 +08:00
namespace ftxui {
2018-10-19 04:58:38 +08:00
// Documentation:
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
//
struct Event {
2018-10-19 04:58:38 +08:00
public:
// --- Constructor section ---------------------------------------------------
static Event Character(char);
static Event Character(wchar_t);
static Event Character(const std::string&);
static Event Special(const std::string&);
static Event GetEvent(std::function<char()> getchar);
2018-10-19 04:58:38 +08:00
// --- Arrow ---
static Event ArrowLeft;
static Event ArrowRight;
static Event ArrowUp;
static Event ArrowDown;
2018-10-19 04:58:38 +08:00
// --- Other ---
static Event Backspace;
static Event Delete;
static Event Return;
static Event Escape;
static Event Tab;
static Event TabReverse;
2018-10-19 04:58:38 +08:00
static Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
2019-01-27 09:33:06 +08:00
// --- Custom ---
static Event Custom;
//--- Method section ---------------------------------------------------------
bool is_character() { return is_character_; }
wchar_t character() { return character_; }
const std::string& input() { return input_; }
2018-10-19 04:58:38 +08:00
bool operator==(const Event& other) { return input_ == other.input_; }
2018-10-19 04:58:38 +08:00
//--- State section ----------------------------------------------------------
private:
std::string input_;
bool is_character_ = false;
2019-07-03 05:09:20 +08:00
wchar_t character_ = U'?';
};
2018-10-19 04:58:38 +08:00
} // namespace ftxui
2018-10-19 04:58:38 +08:00
#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */