Skip to content

Commit 9e36480

Browse files
committed
Fix spurious newline bug
1 parent 74417cc commit 9e36480

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

lldb/include/lldb/Core/Statusline.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ class Statusline {
4545
/// Update terminal dimensions.
4646
void UpdateTerminalProperties();
4747

48-
/// Set the scroll window to the given height.
49-
void SetScrollWindow(uint64_t height);
48+
enum ScrollWindowMode {
49+
ScrollWindowExtend,
50+
ScrollWindowShrink,
51+
};
52+
53+
/// Set the scroll window for the given mode.
54+
void UpdateScrollWindow(ScrollWindowMode mode);
5055

5156
/// Clear the statusline (without redrawing the background).
5257
void Reset();
@@ -57,7 +62,6 @@ class Statusline {
5762
volatile std::sig_atomic_t m_terminal_size_has_changed = 1;
5863
uint64_t m_terminal_width = 0;
5964
uint64_t m_terminal_height = 0;
60-
uint64_t m_scroll_height = 0;
6165
};
6266
} // namespace lldb_private
6367
#endif // LLDB_CORE_STATUSLINE_H

lldb/source/Core/Statusline.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void Statusline::Enable() {
6060
UpdateTerminalProperties();
6161

6262
// Reduce the scroll window to make space for the status bar below.
63-
SetScrollWindow(m_terminal_height - 1);
63+
UpdateScrollWindow(ScrollWindowShrink);
6464

6565
// Draw the statusline.
6666
Redraw();
@@ -70,7 +70,7 @@ void Statusline::Disable() {
7070
UpdateTerminalProperties();
7171

7272
// Extend the scroll window to cover the status bar.
73-
SetScrollWindow(m_terminal_height);
73+
UpdateScrollWindow(ScrollWindowExtend);
7474
}
7575

7676
std::string Statusline::TrimAndPad(std::string str, size_t max_width) {
@@ -153,24 +153,35 @@ void Statusline::UpdateTerminalProperties() {
153153
m_terminal_height = m_debugger.GetTerminalHeight();
154154

155155
// Set the scroll window based on the new terminal height.
156-
SetScrollWindow(m_terminal_height - 1);
156+
UpdateScrollWindow(ScrollWindowShrink);
157157

158158
// Clear the flag.
159159
m_terminal_size_has_changed = 0;
160160
}
161161

162-
void Statusline::SetScrollWindow(uint64_t height) {
163-
if (lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP()) {
164-
LockedStreamFile locked_stream = stream_sp->Lock();
165-
locked_stream << '\n';
166-
locked_stream << ANSI_SAVE_CURSOR;
167-
locked_stream.Printf(ANSI_SET_SCROLL_ROWS, static_cast<unsigned>(height));
168-
locked_stream << ANSI_RESTORE_CURSOR;
169-
locked_stream.Printf(ANSI_UP_ROWS, 1);
162+
void Statusline::UpdateScrollWindow(ScrollWindowMode mode) {
163+
lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP();
164+
if (!stream_sp)
165+
return;
166+
167+
const unsigned scroll_height =
168+
(mode == ScrollWindowExtend) ? m_terminal_height : m_terminal_height - 1;
169+
170+
LockedStreamFile locked_stream = stream_sp->Lock();
171+
locked_stream << ANSI_SAVE_CURSOR;
172+
locked_stream.Printf(ANSI_SET_SCROLL_ROWS, scroll_height);
173+
locked_stream << ANSI_RESTORE_CURSOR;
174+
switch (mode) {
175+
case ScrollWindowExtend:
176+
// Clear the screen below to hide the old statusline.
170177
locked_stream << ANSI_CLEAR_BELOW;
178+
break;
179+
case ScrollWindowShrink:
180+
// Move everything on the screen up.
181+
locked_stream.Printf(ANSI_UP_ROWS, 1);
182+
locked_stream << '\n';
183+
break;
171184
}
172-
173-
m_scroll_height = height;
174185
}
175186

176187
void Statusline::Redraw(bool update) {

0 commit comments

Comments
 (0)