2424#define ANSI_SAVE_CURSOR ESCAPE " 7"
2525#define ANSI_RESTORE_CURSOR ESCAPE " 8"
2626#define ANSI_CLEAR_BELOW ESCAPE " [J"
27- #define ANSI_CURSOR_DOWN ESCAPE " [B"
28- #define ANSI_CLEAR_LINE ESCAPE " [2K"
29- #define ANSI_SET_SCROLL_ROWS ESCAPE " [0;%ur"
30- #define ANSI_TO_START_OF_ROW ESCAPE " [%u;0f"
27+ #define ANSI_CLEAR_SCREEN ESCAPE " [2J"
28+ #define ANSI_SET_SCROLL_ROWS ESCAPE " [1;%ur"
29+ #define ANSI_TO_START_OF_ROW ESCAPE " [%u;1f"
3130#define ANSI_REVERSE_VIDEO ESCAPE " [7m"
3231#define ANSI_UP_ROWS ESCAPE " [%dA"
3332
@@ -43,10 +42,12 @@ Statusline::Statusline(Debugger &debugger)
4342Statusline::~Statusline () { Disable (); }
4443
4544void Statusline::TerminalSizeChanged () {
46- UpdateTerminalProperties ();
45+ m_terminal_width = m_debugger.GetTerminalWidth ();
46+ m_terminal_height = m_debugger.GetTerminalHeight ();
47+
48+ UpdateScrollWindow (ResizeStatusline);
4749
48- // This definitely isn't signal safe, but the best we can do, until we
49- // have proper signal-catching thread.
50+ // Draw the old statusline.
5051 Redraw (/* update=*/ false );
5152}
5253
@@ -87,38 +88,43 @@ void Statusline::Draw(std::string str) {
8788 locked_stream << ANSI_RESTORE_CURSOR;
8889}
8990
90- void Statusline::UpdateTerminalProperties () {
91- UpdateScrollWindow (DisableStatusline);
92- m_terminal_width = m_debugger.GetTerminalWidth ();
93- m_terminal_height = m_debugger.GetTerminalHeight ();
94- UpdateScrollWindow (EnableStatusline);
95- }
96-
9791void Statusline::UpdateScrollWindow (ScrollWindowMode mode) {
9892 assert (m_terminal_width != 0 && m_terminal_height != 0 );
9993
10094 lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP ();
10195 if (!stream_sp)
10296 return ;
10397
104- const unsigned scroll_height =
105- (mode == DisableStatusline) ? m_terminal_height : m_terminal_height - 1 ;
106-
98+ const unsigned reduced_scroll_window = m_terminal_height - 1 ;
10799 LockedStreamFile locked_stream = stream_sp->Lock ();
108- locked_stream << ANSI_SAVE_CURSOR;
109- locked_stream.Printf (ANSI_SET_SCROLL_ROWS, scroll_height);
110- locked_stream << ANSI_RESTORE_CURSOR;
100+
111101 switch (mode) {
112102 case EnableStatusline:
113103 // Move everything on the screen up.
114- locked_stream.Printf (ANSI_UP_ROWS, 1 );
115104 locked_stream << ' \n ' ;
105+ locked_stream.Printf (ANSI_UP_ROWS, 1 );
106+ // Reduce the scroll window.
107+ locked_stream << ANSI_SAVE_CURSOR;
108+ locked_stream.Printf (ANSI_SET_SCROLL_ROWS, reduced_scroll_window);
109+ locked_stream << ANSI_RESTORE_CURSOR;
116110 break ;
117111 case DisableStatusline:
112+ // Reset the scroll window.
113+ locked_stream << ANSI_SAVE_CURSOR;
114+ locked_stream.Printf (ANSI_SET_SCROLL_ROWS, 0 );
115+ locked_stream << ANSI_RESTORE_CURSOR;
118116 // Clear the screen below to hide the old statusline.
119117 locked_stream << ANSI_CLEAR_BELOW;
120118 break ;
119+ case ResizeStatusline:
120+ // Clear the screen and update the scroll window.
121+ // FIXME: Find a better solution (#146919).
122+ locked_stream << ANSI_CLEAR_SCREEN;
123+ locked_stream.Printf (ANSI_SET_SCROLL_ROWS, reduced_scroll_window);
124+ break ;
121125 }
126+
127+ m_debugger.RefreshIOHandler ();
122128}
123129
124130void Statusline::Redraw (bool update) {
0 commit comments