Skip to content

Clear terminal output of interactive screen on resize if alternate screen not in use #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/ftxui/component/screen_interactive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ScreenInteractive : public Screen {
bool mouse_captured = false;
bool previous_frame_resized_ = false;

bool validated_ = false;
bool frame_valid_ = false;

bool force_handle_ctrl_c_ = true;
Expand Down
11 changes: 11 additions & 0 deletions src/ftxui/component/screen_interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,16 @@ void ScreenInteractive::Draw(Component component) {
ResetCursorPosition();
std::cout << ResetPosition(/*clear=*/resized);

// clear terminal output if screen dimx decreases
// only on primary screen
// only on POSIX systems (linux/macos)
#if !defined(_WIN32)
if ((dimx < dimx_) && validated_ && !use_alternative_screen_) {
std::cout << "\033[J"; // clear
std::cout << "\033[H"; // move cursor to home position
}
#endif

// Resize the screen if needed.
if (resized) {
dimx_ = dimx;
Expand Down Expand Up @@ -924,6 +934,7 @@ void ScreenInteractive::Draw(Component component) {
std::cout << ToString() << set_cursor_position;
Flush();
Clear();
validated_ = true;
frame_valid_ = true;
}

Expand Down