Skip to content

[lldb] Use the "reverse video" effect when colors are disabled. #134203

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 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions lldb/source/Core/Statusline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define ANSI_CLEAR_LINE ESCAPE "[2K"
#define ANSI_SET_SCROLL_ROWS ESCAPE "[0;%ur"
#define ANSI_TO_START_OF_ROW ESCAPE "[%u;0f"
#define ANSI_REVERSE_VIDEO ESCAPE "[7m"
#define ANSI_UP_ROWS ESCAPE "[%dA"

using namespace lldb;
Expand Down Expand Up @@ -74,6 +75,12 @@ void Statusline::Draw(std::string str) {
locked_stream << ANSI_SAVE_CURSOR;
locked_stream.Printf(ANSI_TO_START_OF_ROW,
static_cast<unsigned>(m_terminal_height));

// Use "reverse video" to make sure the statusline has a background. Only do
// this when colors are disabled, and rely on the statusline format otherwise.
if (!m_debugger.GetUseColor())
locked_stream << ANSI_REVERSE_VIDEO;

locked_stream << str;
locked_stream << ANSI_NORMAL;
locked_stream << ANSI_RESTORE_CURSOR;
Expand Down
22 changes: 22 additions & 0 deletions lldb/test/API/functionalities/statusline/TestStatusline.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,25 @@ def test(self):
self.expect(
"set set show-statusline false", ["\x1b[0;{}r".format(terminal_height)]
)

# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
@skipIfAsan
def test_no_color(self):
"""Basic test for the statusline with colors disabled."""
self.build()
self.launch(use_colors=False)
self.do_setup()

# Change the terminal dimensions.
terminal_height = 10
terminal_width = 60
self.child.setwinsize(terminal_height, terminal_width)

# Enable the statusline and check for the "reverse video" control character.
self.expect(
"set set show-statusline true",
[
"\x1b[7m",
],
)