Skip to content

Commit 785b196

Browse files
committed
[lldb] Make the statusline separator configurable (llvm#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. (cherry picked from commit 6f1adbd) Conflicts: lldb/source/Core/Debugger.cpp
1 parent d40537c commit 785b196

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
312312

313313
const FormatEntity::Entry *GetStatuslineFormat() const;
314314

315+
llvm::StringRef GetSeparator() const;
316+
bool SetSeparator(llvm::StringRef s);
317+
315318
llvm::StringRef GetShowProgressAnsiPrefix() const;
316319

317320
llvm::StringRef GetShowProgressAnsiSuffix() const;

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,19 @@ let Definition = "debugger" in {
229229
Global,
230230
DefaultTrue,
231231
Desc<"Whether to show a statusline at the bottom of the terminal.">;
232-
def StatuslineFormat: Property<"statusline-format", "FormatEntity">,
233-
Global,
234-
DefaultStringValue<"${ansi.negative}{${target.file.basename}}{ | ${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ | {${progress.count} }${progress.message}}">,
235-
Desc<"The default statusline format string.">;
232+
def Separator : Property<"separator", "String">,
233+
Global,
234+
DefaultStringValue<"│ ">,
235+
Desc<"A separator used, e.g., in the status line.">;
236+
def StatuslineFormat
237+
: Property<"statusline-format", "FormatEntity">,
238+
Global,
239+
DefaultStringValue<
240+
"${ansi.negative}{${target.file.basename}}{ "
241+
"${separator}${line.file.basename}:${line.number}:${line.column}}{ "
242+
"${separator}${thread.stop-reason}}{ "
243+
"${separator}{${progress.count} }${progress.message}}">,
244+
Desc<"The default statusline format string.">;
236245
def UseSourceCache: Property<"use-source-cache", "Boolean">,
237246
Global,
238247
DefaultTrue,

lldb/source/Core/Debugger.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,19 @@ const FormatEntity::Entry *Debugger::GetStatuslineFormat() const {
483483
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
484484
}
485485

486+
llvm::StringRef Debugger::GetSeparator() const {
487+
constexpr uint32_t idx = ePropertySeparator;
488+
return GetPropertyAtIndexAs<llvm::StringRef>(
489+
idx, g_debugger_properties[idx].default_cstr_value);
490+
}
491+
492+
bool Debugger::SetSeparator(llvm::StringRef s) {
493+
constexpr uint32_t idx = ePropertySeparator;
494+
bool ret = SetPropertyAtIndex(idx, s);
495+
RedrawStatusline();
496+
return ret;
497+
}
498+
486499
bool Debugger::GetUseAutosuggestion() const {
487500
const uint32_t idx = ePropertyShowAutosuggestion;
488501
return GetPropertyAtIndexAs<bool>(
@@ -976,11 +989,16 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
976989

977990
// Turn off use-color if this is a dumb terminal.
978991
const char *term = getenv("TERM");
979-
if (term && !strcmp(term, "dumb"))
992+
auto disable_color = [&]() {
980993
SetUseColor(false);
994+
SetSeparator("| ");
995+
};
996+
997+
if (term && !strcmp(term, "dumb"))
998+
disable_color();
981999
// Turn off use-color if we don't write to a terminal with color support.
9821000
if (!GetOutputFileSP()->GetIsTerminalWithColors())
983-
SetUseColor(false);
1001+
disable_color();
9841002

9851003
if (Diagnostics::Enabled()) {
9861004
m_diagnostics_callback_id = Diagnostics::Instance().AddCallback(

lldb/source/Core/FormatEntity.cpp

Lines changed: 9 additions & 0 deletions
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
}
@@ -1947,6 +1949,13 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
19471949
}
19481950
}
19491951
return false;
1952+
1953+
case Entry::Type::Separator:
1954+
if (Target *target = Target::GetTargetFromContexts(exe_ctx, sc)) {
1955+
s << target->GetDebugger().GetSeparator();
1956+
return true;
1957+
}
1958+
return false;
19501959
}
19511960

19521961
return false;

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

Lines changed: 5 additions & 2 deletions
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)