Skip to content

Commit 6f1adbd

Browse files
[lldb] Make the statusline separator configurable (#136611)
And use this functionality to replace the ASCII "|" with the same full-geight line-drawing character used in diagnostics rendering on a color terminal.
1 parent 66b2c34 commit 6f1adbd

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

lldb/include/lldb/Core/Debugger.h

+3
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
303303
const FormatEntity::Entry *GetStatuslineFormat() const;
304304
bool SetStatuslineFormat(const FormatEntity::Entry &format);
305305

306+
llvm::StringRef GetSeparator() const;
307+
bool SetSeparator(llvm::StringRef s);
308+
306309
llvm::StringRef GetShowProgressAnsiPrefix() const;
307310

308311
llvm::StringRef GetShowProgressAnsiSuffix() const;

lldb/include/lldb/Core/FormatEntity.h

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct Entry {
103103
CurrentPCArrow,
104104
ProgressCount,
105105
ProgressMessage,
106+
Separator,
106107
};
107108

108109
struct Definition {

lldb/source/Core/CoreProperties.td

+13-4
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,19 @@ let Definition = "debugger" in {
176176
Global,
177177
DefaultTrue,
178178
Desc<"Whether to show a statusline at the bottom of the terminal.">;
179-
def StatuslineFormat: Property<"statusline-format", "FormatEntity">,
180-
Global,
181-
DefaultStringValue<"${ansi.negative}{${target.file.basename}}{ | ${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ | {${progress.count} }${progress.message}}">,
182-
Desc<"The default statusline format string.">;
179+
def Separator : Property<"separator", "String">,
180+
Global,
181+
DefaultStringValue<"│ ">,
182+
Desc<"A separator used, e.g., in the status line.">;
183+
def StatuslineFormat
184+
: Property<"statusline-format", "FormatEntity">,
185+
Global,
186+
DefaultStringValue<
187+
"${ansi.negative}{${target.file.basename}}{ "
188+
"${separator}${line.file.basename}:${line.number}:${line.column}}{ "
189+
"${separator}${thread.stop-reason}}{ "
190+
"${separator}{${progress.count} }${progress.message}}">,
191+
Desc<"The default statusline format string.">;
183192
def UseSourceCache: Property<"use-source-cache", "Boolean">,
184193
Global,
185194
DefaultTrue,

lldb/source/Core/Debugger.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,19 @@ bool Debugger::SetStatuslineFormat(const FormatEntity::Entry &format) {
502502
return ret;
503503
}
504504

505+
llvm::StringRef Debugger::GetSeparator() const {
506+
constexpr uint32_t idx = ePropertySeparator;
507+
return GetPropertyAtIndexAs<llvm::StringRef>(
508+
idx, g_debugger_properties[idx].default_cstr_value);
509+
}
510+
511+
bool Debugger::SetSeparator(llvm::StringRef s) {
512+
constexpr uint32_t idx = ePropertySeparator;
513+
bool ret = SetPropertyAtIndex(idx, s);
514+
RedrawStatusline();
515+
return ret;
516+
}
517+
505518
bool Debugger::GetUseAutosuggestion() const {
506519
const uint32_t idx = ePropertyShowAutosuggestion;
507520
return GetPropertyAtIndexAs<bool>(
@@ -1001,11 +1014,16 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
10011014

10021015
// Turn off use-color if this is a dumb terminal.
10031016
const char *term = getenv("TERM");
1004-
if (term && !strcmp(term, "dumb"))
1017+
auto disable_color = [&]() {
10051018
SetUseColor(false);
1019+
SetSeparator("| ");
1020+
};
1021+
1022+
if (term && !strcmp(term, "dumb"))
1023+
disable_color();
10061024
// Turn off use-color if we don't write to a terminal with color support.
10071025
if (!GetOutputFileSP()->GetIsTerminalWithColors())
1008-
SetUseColor(false);
1026+
disable_color();
10091027

10101028
if (Diagnostics::Enabled()) {
10111029
m_diagnostics_callback_id = Diagnostics::Instance().AddCallback(

lldb/source/Core/FormatEntity.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ constexpr Definition g_top_level_entries[] = {
266266
g_var_child_entries, true),
267267
Entry::DefinitionWithChildren("progress", EntryType::Invalid,
268268
g_progress_child_entries),
269+
Definition("separator", EntryType::Separator),
269270
};
270271

271272
constexpr Definition g_root = Entry::DefinitionWithChildren(
@@ -367,6 +368,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
367368
ENUM_TO_CSTR(CurrentPCArrow);
368369
ENUM_TO_CSTR(ProgressCount);
369370
ENUM_TO_CSTR(ProgressMessage);
371+
ENUM_TO_CSTR(Separator);
370372
}
371373
return "???";
372374
}
@@ -1901,6 +1903,13 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
19011903
}
19021904
}
19031905
return false;
1906+
1907+
case Entry::Type::Separator:
1908+
if (Target *target = Target::GetTargetFromContexts(exe_ctx, sc)) {
1909+
s << target->GetDebugger().GetSeparator();
1910+
return true;
1911+
}
1912+
return false;
19041913
}
19051914

19061915
return false;

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test(self):
3232

3333
# Enable the statusline and check for the control character and that we
3434
# can see the target, the location and the stop reason.
35+
self.expect('set set separator "| "')
3536
self.expect(
3637
"set set show-statusline true",
3738
[
@@ -46,10 +47,12 @@ def test(self):
4647
self.child.setwinsize(terminal_height, terminal_width)
4748

4849
# Change the format.
50+
self.expect('set set separator "S"')
4951
self.expect(
50-
'set set statusline-format "target = {${target.file.basename}}"',
51-
["target = a.out"],
52+
'set set statusline-format "target = {${target.file.basename}} ${separator}"',
53+
["target = a.out S"],
5254
)
55+
self.expect('set set separator "| "')
5356

5457
# Hide the statusline and check or the control character.
5558
self.expect(

0 commit comments

Comments
 (0)