[Lldb-commits] [lldb] 097d46f - [lldb] Add a setting to change the progress color
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 8 18:26:55 PST 2022
Author: Jonas Devlieghere
Date: 2022-03-08T18:25:10-08:00
New Revision: 097d46f41c46a5e03bac673d264754628775b055
URL: https://github.com/llvm/llvm-project/commit/097d46f41c46a5e03bac673d264754628775b055
DIFF: https://github.com/llvm/llvm-project/commit/097d46f41c46a5e03bac673d264754628775b055.diff
LOG: [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
Added:
Modified:
lldb/include/lldb/Core/Debugger.h
lldb/source/Core/CoreProperties.td
lldb/source/Core/Debugger.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index ec6645986310f..dbdb1431f3d59 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -331,6 +331,10 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
bool GetShowProgress() const;
+ llvm::StringRef GetShowProgressAnsiPrefix() const;
+
+ llvm::StringRef GetShowProgressAnsiSuffix() const;
+
bool GetUseAutosuggestion() const;
llvm::StringRef GetAutosuggestionAnsiPrefix() const;
diff --git a/lldb/source/Core/CoreProperties.td b/lldb/source/Core/CoreProperties.td
index 04e2f4e1060d6..494cc473d0f69 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -135,6 +135,14 @@ let Definition = "debugger" in {
Global,
DefaultTrue,
Desc<"Whether to show progress or not if the debugger's output is an interactive color-enabled terminal.">;
+ def ShowProgressAnsiPrefix: Property<"show-progress-ansi-prefix", "String">,
+ Global,
+ DefaultStringValue<"${ansi.faint}">,
+ Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the progress message.">;
+ def ShowProgressAnsiSuffix: Property<"show-progress-ansi-suffix", "String">,
+ Global,
+ DefaultStringValue<"${ansi.normal}">,
+ Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the progress message.">;
def UseSourceCache: Property<"use-source-cache", "Boolean">,
Global,
DefaultTrue,
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 4df7c9800d750..622dd6626423c 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -384,6 +384,16 @@ bool Debugger::GetShowProgress() const {
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
}
+llvm::StringRef Debugger::GetShowProgressAnsiPrefix() const {
+ const uint32_t idx = ePropertyShowProgressAnsiPrefix;
+ return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
+}
+
+llvm::StringRef Debugger::GetShowProgressAnsiSuffix() const {
+ const uint32_t idx = ePropertyShowProgressAnsiSuffix;
+ return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
+}
+
bool Debugger::GetUseAutosuggestion() const {
const uint32_t idx = ePropertyShowAutosuggestion;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
@@ -1779,6 +1789,12 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
return;
}
+ const bool use_color = GetUseColor();
+ llvm::StringRef ansi_prefix = GetShowProgressAnsiPrefix();
+ if (!ansi_prefix.empty())
+ output.Printf(
+ "%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str());
+
// Print over previous line, if any.
output.Printf("\r");
@@ -1791,6 +1807,11 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
output.Printf("%s...", message.c_str());
}
+ llvm::StringRef ansi_suffix = GetShowProgressAnsiSuffix();
+ if (!ansi_suffix.empty())
+ output.Printf(
+ "%s", ansi::FormatAnsiTerminalCodes(ansi_suffix, use_color).c_str());
+
// Clear until the end of the line.
output.Printf("\x1B[K");
More information about the lldb-commits
mailing list