Enable mouse tracking.

Request terminal to send mouse position.

See:
https://github.com/ArthurSonzogni/FTXUI/issues/7
This commit is contained in:
ArthurSonzogni 2021-04-05 22:03:37 +02:00
parent cac94439ff
commit 476b9deaf8
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C

View File

@ -146,14 +146,17 @@ void EventListener(std::atomic<bool>* quit, Sender<Event> out) {
#endif
static const char* HIDE_CURSOR = "\x1B[?25l";
static const char* SHOW_CURSOR = "\x1B[?25h";
static const char SHOW_CURSOR[] = "\x1B[?25h";
static const char HIDE_CURSOR[] = "\x1B[?25l";
static const char* DISABLE_LINE_WRAP = "\x1B[7l";
static const char* ENABLE_LINE_WRAP = "\x1B[7h";
static const char ENABLE_LINE_WRAP[] = "\x1B[7h";
static const char DISABLE_LINE_WRAP[] = "\x1B[7l";
static const char* USE_ALTERNATIVE_SCREEN = "\x1B[?1049h";
static const char* USE_NORMAL_SCREEN = "\x1B[?1049l";
static const char USE_ALTERNATIVE_SCREEN[] = "\x1B[?1049h";
static const char USE_NORMAL_SCREEN[] = "\x1B[?1049l";
static const char ENABLE_MOUSE[] = "\x1B[?1000;1006;1015h";
static const char DISABLE_MOUSE[] = "\x1B[?1000;10006;1015l";
using SignalHandler = void(int);
std::stack<std::function<void()>> on_exit_functions;
@ -279,6 +282,9 @@ void ScreenInteractive::Loop(Component* component) {
on_exit_functions.push([] { std::cout << USE_NORMAL_SCREEN; });
}
std::cout << ENABLE_MOUSE;
on_exit_functions.push([] { std::cout << DISABLE_MOUSE; });
// Hide the cursor and show it at exit.
std::cout << HIDE_CURSOR;
std::cout << DISABLE_LINE_WRAP;