JDevlieghere updated this revision to Diff 411533.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120593/new/
https://reviews.llvm.org/D120593
Files:
lldb/tools/driver/Driver.cpp
llvm/include/llvm/Support/WithColor.h
llvm/lib/Support/WithColor.cpp
Index: llvm/lib/Support/WithColor.cpp
===================================================================
--- llvm/lib/Support/WithColor.cpp
+++ llvm/lib/Support/WithColor.cpp
@@ -33,6 +33,9 @@
static ManagedStatic<cl::opt<cl::boolOrDefault>, CreateUseColor> UseColor;
void llvm::initWithColorOptions() { *UseColor; }
+WithColor::AutoDetectFunctionType WithColor::AutoDetectFunction =
+ WithColor::defaultAutoDetectFunction();
+
WithColor::WithColor(raw_ostream &OS, HighlightColor Color, ColorMode Mode)
: OS(OS), Mode(Mode) {
// Detect color from terminal type unless the user passed the --color option.
@@ -127,8 +130,7 @@
case ColorMode::Disable:
return false;
case ColorMode::Auto:
- return *UseColor == cl::BOU_UNSET ? OS.has_colors()
- : *UseColor == cl::BOU_TRUE;
+ return AutoDetectFunction(OS);
}
llvm_unreachable("All cases handled above.");
}
@@ -159,3 +161,15 @@
WithColor::warning() << Info.message() << '\n';
});
}
+
+WithColor::AutoDetectFunctionType WithColor::defaultAutoDetectFunction() {
+ return [](const raw_ostream &OS) {
+ return *UseColor == cl::BOU_UNSET ? OS.has_colors()
+ : *UseColor == cl::BOU_TRUE;
+ };
+}
+
+void WithColor::setAutoDetectFunction(
+ AutoDetectFunctionType NewAutoDetectFunction) {
+ AutoDetectFunction = std::move(NewAutoDetectFunction);
+}
Index: llvm/include/llvm/Support/WithColor.h
===================================================================
--- llvm/include/llvm/Support/WithColor.h
+++ llvm/include/llvm/Support/WithColor.h
@@ -11,6 +11,8 @@
#include "llvm/Support/raw_ostream.h"
+#include <functional>
+
namespace llvm {
class Error;
@@ -54,6 +56,9 @@
raw_ostream &OS;
ColorMode Mode;
+ using AutoDetectFunctionType = std::function<bool(const raw_ostream &OS)>;
+ static AutoDetectFunctionType AutoDetectFunction;
+
public:
/// To be used like this: WithColor(OS, HighlightColor::String) << "text";
/// @param OS The output stream
@@ -132,6 +137,13 @@
/// Implement default handling for Warning.
/// Print "warning: " to stderr.
static void defaultWarningHandler(Error Warning);
+
+ /// Retrieve the default color auto detection function.
+ static AutoDetectFunctionType defaultAutoDetectFunction();
+
+ /// Change the global auto detection function.
+ static void
+ setAutoDetectFunction(AutoDetectFunctionType NewAutoDetectFunction);
};
} // end namespace llvm
Index: lldb/tools/driver/Driver.cpp
===================================================================
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -186,6 +186,13 @@
m_debugger.SkipLLDBInitFiles(false);
m_debugger.SkipAppInitFiles(false);
+ if (args.hasArg(OPT_no_use_colors)) {
+ m_debugger.SetUseColor(false);
+ WithColor::setAutoDetectFunction(
+ [](const llvm::raw_ostream &OS) { return false; });
+ m_option_data.m_debug_mode = true;
+ }
+
if (args.hasArg(OPT_version)) {
m_option_data.m_print_version = true;
}
@@ -227,11 +234,6 @@
m_debugger.GetInstanceName());
}
- if (args.hasArg(OPT_no_use_colors)) {
- m_debugger.SetUseColor(false);
- m_option_data.m_debug_mode = true;
- }
-
if (auto *arg = args.getLastArg(OPT_file)) {
auto arg_value = arg->getValue();
SBFileSpec file(arg_value);
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits