From dfa461b46b9098d566f73072827b9204315ffde2 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov <113844030+dangooddd@users.noreply.github.com> Date: Wed, 27 Nov 2024 23:52:20 +0300 Subject: [PATCH] Clear terminal output of interactive screen on resize if alternate screen not in use (#952) --- src/ftxui/component/screen_interactive.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index b5643ed..45a4fff 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -858,6 +858,13 @@ void ScreenInteractive::Draw(Component component) { ResetCursorPosition(); std::cout << ResetPosition(/*clear=*/resized); + // If the terminal width decrease, the terminal emulator will start wrapping + // lines and make the display dirty. We should clear it completely. + if ((dimx < dimx_) && !use_alternative_screen_) { + std::cout << "\033[J"; // clear terminal output + std::cout << "\033[H"; // move cursor to home position + } + // Resize the screen if needed. if (resized) { dimx_ = dimx;