diff --git a/CHANGELOG.md b/CHANGELOG.md index 163ab1cb5..c9109b1fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ current (development) Component Slider(SliderOption options); Component ResizableSplit(ResizableSplitOption options); ``` +- Feature: Add `ScreenInteractive::TrackMouse(false)` disable mouse support. ### Dom - Feature: Add `hyperlink` decorator. For instance: diff --git a/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp index f038c35c6..ec08765db 100644 --- a/include/ftxui/component/screen_interactive.hpp +++ b/include/ftxui/component/screen_interactive.hpp @@ -31,6 +31,9 @@ class ScreenInteractive : public Screen { static ScreenInteractive FitComponent(); static ScreenInteractive TerminalOutput(); + // Options. Must be called before Loop(). + void TrackMouse(bool enable = true); + // Return the currently active screen, nullptr if none. static ScreenInteractive* Active(); @@ -84,6 +87,8 @@ class ScreenInteractive : public Screen { Dimension dimension, bool use_alternative_screen); + bool track_mouse_= true; + Sender task_sender_; Receiver task_receiver_; diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 290077109..ddaabcb67 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -379,6 +379,26 @@ ScreenInteractive ScreenInteractive::FitComponent() { }; } +/// @ingroup component +/// @brief Set whether mouse is tracked and events reported. +/// called outside of the main loop. E.g `ScreenInteractive::Loop(...)`. +/// @param enable Whether to enable mouse event tracking. +/// @note This muse be called outside of the main loop. E.g. before calling +/// `ScreenInteractive::Loop`. +/// @note Mouse tracking is enabled by default. +/// @note Mouse tracking is only supported on terminals that supports it. +/// +/// ### Example +/// +/// ```cpp +/// auto screen = ScreenInteractive::TerminalOutput(); +/// screen.TrackMouse(false); +/// screen.Loop(component); +/// ``` +void ScreenInteractive::TrackMouse(bool enable) { + track_mouse_ = enable; +} + void ScreenInteractive::Post(Task task) { // Task/Events sent toward inactive screen or screen waiting to become // inactive are dropped. @@ -580,10 +600,12 @@ void ScreenInteractive::Install() { DECMode::kLineWrap, }); - enable({DECMode::kMouseVt200}); - enable({DECMode::kMouseAnyEvent}); - enable({DECMode::kMouseUrxvtMode}); - enable({DECMode::kMouseSgrExtMode}); + if (track_mouse_) { + enable({DECMode::kMouseVt200}); + enable({DECMode::kMouseAnyEvent}); + enable({DECMode::kMouseUrxvtMode}); + enable({DECMode::kMouseSgrExtMode}); + } // After installing the new configuration, flush it to the terminal to // ensure it is fully applied: