From 476b9deaf8894b6fe7797bcc14b4d782582c1244 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Mon, 5 Apr 2021 22:03:37 +0200 Subject: [PATCH] Enable mouse tracking. Request terminal to send mouse position. See: https://github.com/ArthurSonzogni/FTXUI/issues/7 --- src/ftxui/component/screen_interactive.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index b4f3753..4c3eb29 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -146,14 +146,17 @@ void EventListener(std::atomic* quit, Sender 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> 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;