Skip to content

Commit a66ee6a

Browse files
JDevliegheregithub-actions[bot]
authored andcommitted
Automerge: [lldb] Use the "reverse video" effect when colors are disabled. (#134203)
When you run lldb without colors (`-X`), the status line looks weird because it doesn't have a background. You end up with what appears to be floating text at the bottom of your terminal. This patch changes the statusline to use the reverse video effect, even when colors are off. The effect doesn't introduce any new colors and just inverts the foreground and background color. I considered an alternative approach which changes the behavior of the `-X` option, so that turning off colors doesn't prevent emitting non-color related control characters such as bold, underline, and reverse video. I decided to go with this more targeted fix as (1) nobody is asking for this more general change and (2) it introduces significant complexity to plumb this through using a setting and driver flag so that it can be disabled when running the tests. Fixes #134112.
2 parents c8fadd9 + 5f99e0d commit a66ee6a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lldb/source/Core/Statusline.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define ANSI_CLEAR_LINE ESCAPE "[2K"
2828
#define ANSI_SET_SCROLL_ROWS ESCAPE "[0;%ur"
2929
#define ANSI_TO_START_OF_ROW ESCAPE "[%u;0f"
30+
#define ANSI_REVERSE_VIDEO ESCAPE "[7m"
3031
#define ANSI_UP_ROWS ESCAPE "[%dA"
3132

3233
using namespace lldb;
@@ -74,6 +75,12 @@ void Statusline::Draw(std::string str) {
7475
locked_stream << ANSI_SAVE_CURSOR;
7576
locked_stream.Printf(ANSI_TO_START_OF_ROW,
7677
static_cast<unsigned>(m_terminal_height));
78+
79+
// Use "reverse video" to make sure the statusline has a background. Only do
80+
// this when colors are disabled, and rely on the statusline format otherwise.
81+
if (!m_debugger.GetUseColor())
82+
locked_stream << ANSI_REVERSE_VIDEO;
83+
7784
locked_stream << str;
7885
locked_stream << ANSI_NORMAL;
7986
locked_stream << ANSI_RESTORE_CURSOR;

lldb/test/API/functionalities/statusline/TestStatusline.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,25 @@ def test(self):
5555
self.expect(
5656
"set set show-statusline false", ["\x1b[0;{}r".format(terminal_height)]
5757
)
58+
59+
# PExpect uses many timeouts internally and doesn't play well
60+
# under ASAN on a loaded machine..
61+
@skipIfAsan
62+
def test_no_color(self):
63+
"""Basic test for the statusline with colors disabled."""
64+
self.build()
65+
self.launch(use_colors=False)
66+
self.do_setup()
67+
68+
# Change the terminal dimensions.
69+
terminal_height = 10
70+
terminal_width = 60
71+
self.child.setwinsize(terminal_height, terminal_width)
72+
73+
# Enable the statusline and check for the "reverse video" control character.
74+
self.expect(
75+
"set set show-statusline true",
76+
[
77+
"\x1b[7m",
78+
],
79+
)

0 commit comments

Comments
 (0)