https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/146435
Avoid some of the work to disable/enable the statusline when the terminal dimensions change. >From 73bffa08fe1b2946a81056636b505f93d0b787a8 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Mon, 30 Jun 2025 16:30:27 -0700 Subject: [PATCH] [lldb] Optimize statusline redrawing on terminal size change Avoid some of the work to disable/enable the statusline when the terminal dimensions change. --- lldb/include/lldb/Core/Statusline.h | 3 --- lldb/source/Core/Statusline.cpp | 29 +++++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lldb/include/lldb/Core/Statusline.h b/lldb/include/lldb/Core/Statusline.h index 521b9f2526f6b..98c4f0681d61e 100644 --- a/lldb/include/lldb/Core/Statusline.h +++ b/lldb/include/lldb/Core/Statusline.h @@ -36,9 +36,6 @@ class Statusline { /// Draw the statusline with the given text. void Draw(std::string msg); - /// Update terminal dimensions. - void UpdateTerminalProperties(); - enum ScrollWindowMode { EnableStatusline, DisableStatusline, diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp index 8ec57c9fa5bac..327ba0ea62465 100644 --- a/lldb/source/Core/Statusline.cpp +++ b/lldb/source/Core/Statusline.cpp @@ -41,10 +41,26 @@ Statusline::Statusline(Debugger &debugger) Statusline::~Statusline() { Disable(); } void Statusline::TerminalSizeChanged() { - UpdateTerminalProperties(); + const uint64_t terminal_width = m_debugger.GetTerminalWidth(); + const uint64_t terminal_height = m_debugger.GetTerminalHeight(); + + // Remember whether the terminal height changed. + const bool terminal_height_changed = terminal_height != m_terminal_height; + + // Avoid clearing the old statusline if it's not visible (i.e. when the + // terminal height decreases), unless the width changed and the old statusline + // wrapped. + if (terminal_height > m_terminal_height || terminal_width < m_terminal_width) + UpdateScrollWindow(DisableStatusline); + + // Update the terminal dimensions. + m_terminal_width = terminal_width; + m_terminal_height = terminal_height; + + // Update the scroll window if the terminal height changed. + if (terminal_height_changed) + UpdateScrollWindow(EnableStatusline); - // This definitely isn't signal safe, but the best we can do, until we - // have proper signal-catching thread. Redraw(/*update=*/false); } @@ -85,13 +101,6 @@ void Statusline::Draw(std::string str) { locked_stream << ANSI_RESTORE_CURSOR; } -void Statusline::UpdateTerminalProperties() { - UpdateScrollWindow(DisableStatusline); - m_terminal_width = m_debugger.GetTerminalWidth(); - m_terminal_height = m_debugger.GetTerminalHeight(); - UpdateScrollWindow(EnableStatusline); -} - void Statusline::UpdateScrollWindow(ScrollWindowMode mode) { assert(m_terminal_width != 0 && m_terminal_height != 0); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits