Skip to content

Commit 097d46f

Browse files
committed
[lldb] Add a setting to change the progress color
Add a setting to change how progress is shown in a color enabled terminal. This follows the existing -prefix, -suffix pattern that's used elsewhere in lldb. Differential revision: https://reviews.llvm.org/D121062
1 parent 5a27b99 commit 097d46f

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
331331

332332
bool GetShowProgress() const;
333333

334+
llvm::StringRef GetShowProgressAnsiPrefix() const;
335+
336+
llvm::StringRef GetShowProgressAnsiSuffix() const;
337+
334338
bool GetUseAutosuggestion() const;
335339

336340
llvm::StringRef GetAutosuggestionAnsiPrefix() const;

lldb/source/Core/CoreProperties.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ let Definition = "debugger" in {
135135
Global,
136136
DefaultTrue,
137137
Desc<"Whether to show progress or not if the debugger's output is an interactive color-enabled terminal.">;
138+
def ShowProgressAnsiPrefix: Property<"show-progress-ansi-prefix", "String">,
139+
Global,
140+
DefaultStringValue<"${ansi.faint}">,
141+
Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the progress message.">;
142+
def ShowProgressAnsiSuffix: Property<"show-progress-ansi-suffix", "String">,
143+
Global,
144+
DefaultStringValue<"${ansi.normal}">,
145+
Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the progress message.">;
138146
def UseSourceCache: Property<"use-source-cache", "Boolean">,
139147
Global,
140148
DefaultTrue,

lldb/source/Core/Debugger.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ bool Debugger::GetShowProgress() const {
384384
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
385385
}
386386

387+
llvm::StringRef Debugger::GetShowProgressAnsiPrefix() const {
388+
const uint32_t idx = ePropertyShowProgressAnsiPrefix;
389+
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
390+
}
391+
392+
llvm::StringRef Debugger::GetShowProgressAnsiSuffix() const {
393+
const uint32_t idx = ePropertyShowProgressAnsiSuffix;
394+
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
395+
}
396+
387397
bool Debugger::GetUseAutosuggestion() const {
388398
const uint32_t idx = ePropertyShowAutosuggestion;
389399
return m_collection_sp->GetPropertyAtIndexAsBoolean(
@@ -1779,6 +1789,12 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
17791789
return;
17801790
}
17811791

1792+
const bool use_color = GetUseColor();
1793+
llvm::StringRef ansi_prefix = GetShowProgressAnsiPrefix();
1794+
if (!ansi_prefix.empty())
1795+
output.Printf(
1796+
"%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str());
1797+
17821798
// Print over previous line, if any.
17831799
output.Printf("\r");
17841800

@@ -1791,6 +1807,11 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
17911807
output.Printf("%s...", message.c_str());
17921808
}
17931809

1810+
llvm::StringRef ansi_suffix = GetShowProgressAnsiSuffix();
1811+
if (!ansi_suffix.empty())
1812+
output.Printf(
1813+
"%s", ansi::FormatAnsiTerminalCodes(ansi_suffix, use_color).c_str());
1814+
17941815
// Clear until the end of the line.
17951816
output.Printf("\x1B[K");
17961817

0 commit comments

Comments
 (0)