From 1888631becd57fdc2475931a90014f8bd539d24d Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Tue, 11 Jan 2022 23:06:36 +0100 Subject: [PATCH] Main (#303) * Refresh cursor reporting on resize. * Fix invalid size write. This resolves: https://github.com/ArthurSonzogni/FTXUI/issues/302 --- .../ftxui/component/screen_interactive.hpp | 1 + src/ftxui/component/component.cpp | 3 ++- src/ftxui/component/screen_interactive.cpp | 26 ++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp index e6b0518..6d3d605 100644 --- a/include/ftxui/component/screen_interactive.hpp +++ b/include/ftxui/component/screen_interactive.hpp @@ -66,6 +66,7 @@ class ScreenInteractive : public Screen { int cursor_y_ = 1; bool mouse_captured = false; + bool previous_frame_resized_ = false; }; } // namespace ftxui diff --git a/src/ftxui/component/component.cpp b/src/ftxui/component/component.cpp index 21c70ca..3bd9e90 100644 --- a/src/ftxui/component/component.cpp +++ b/src/ftxui/component/component.cpp @@ -64,8 +64,9 @@ void ComponentBase::Detach() { [this](const Component& that) { // return this == that.get(); }); - parent_->children_.erase(it); + ComponentBase* parent = parent_; parent_ = nullptr; + parent->children_.erase(it); // Might delete |this|. } /// @brief Remove all children. diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 4017cc1..439b082 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -488,22 +488,24 @@ void ScreenInteractive::Draw(Component component) { // Periodically request the terminal emulator the frame position relative to // the screen. This is useful for converting mouse position reported in // screen's coordinates to frame's coordinates. - static constexpr int cursor_refresh_rate = #if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK) - // Microsoft's terminal suffers from a [bug]. When reporting the cursor - // position, several output sequences are mixed together into garbage. - // This causes FTXUI user to see some "1;1;R" sequences into the Input - // component. See [issue]. Solution is to request cursor position less - // often. [bug]: https://github.com/microsoft/terminal/pull/7583 [issue]: - // https://github.com/ArthurSonzogni/FTXUI/issues/136 - 150; -#else - 20; -#endif + // Microsoft's terminal suffers from a [bug]. When reporting the cursor + // position, several output sequences are mixed together into garbage. + // This causes FTXUI user to see some "1;1;R" sequences into the Input + // component. See [issue]. Solution is to request cursor position less + // often. [bug]: https://github.com/microsoft/terminal/pull/7583 [issue]: + // https://github.com/ArthurSonzogni/FTXUI/issues/136 static int i = -3; ++i; - if (!use_alternative_screen_ && (i % cursor_refresh_rate == 0)) + if (!use_alternative_screen_ && (i % 150 == 0)) std::cout << DeviceStatusReport(DSRMode::kCursor); +#else + static int i = -3; + ++i; + if (!use_alternative_screen_ && (previous_frame_resized_ || i % 40 == 0)) + std::cout << DeviceStatusReport(DSRMode::kCursor); +#endif + previous_frame_resized_ = resized; Render(*this, document);