* Refresh cursor reporting on resize.

* Fix invalid size write.

This resolves:
https://github.com/ArthurSonzogni/FTXUI/issues/302
This commit is contained in:
Arthur Sonzogni 2022-01-11 23:06:36 +01:00 committed by GitHub
parent 84299de2e1
commit 1888631bec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View File

@ -66,6 +66,7 @@ class ScreenInteractive : public Screen {
int cursor_y_ = 1;
bool mouse_captured = false;
bool previous_frame_resized_ = false;
};
} // namespace ftxui

View File

@ -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.

View File

@ -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);