static bool g_old_stdin_termios_is_valid = false;
static struct termios g_old_stdin_termios;
+static bool disable_color(const raw_ostream &OS) { return false; }
+
static Driver *g_driver = nullptr;
// In the Driver::MainLoop, we change the terminal settings. This function is
m_debugger.SkipLLDBInitFiles(false);
m_debugger.SkipAppInitFiles(false);
+ if (args.hasArg(OPT_no_use_colors)) {
+ m_debugger.SetUseColor(false);
+ WithColor::setAutoDetectFunction(disable_color);
+ m_option_data.m_debug_mode = true;
+ }
+
if (args.hasArg(OPT_version)) {
m_option_data.m_print_version = true;
}
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);
/// An RAII object that temporarily switches an output stream to a specific
/// color.
class WithColor {
- raw_ostream &OS;
- ColorMode Mode;
-
public:
+ using AutoDetectFunctionType = bool (*)(const raw_ostream &OS);
+
/// To be used like this: WithColor(OS, HighlightColor::String) << "text";
/// @param OS The output stream
/// @param S Symbolic name for syntax element to color
/// 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);
+
+private:
+ raw_ostream &OS;
+ ColorMode Mode;
+
+ static AutoDetectFunctionType AutoDetectFunction;
};
} // end namespace llvm
static ManagedStatic<cl::opt<cl::boolOrDefault>, CreateUseColor> UseColor;
void llvm::initWithColorOptions() { *UseColor; }
+static bool DefaultAutoDetectFunction(const raw_ostream &OS) {
+ return *UseColor == cl::BOU_UNSET ? OS.has_colors()
+ : *UseColor == cl::BOU_TRUE;
+}
+
+WithColor::AutoDetectFunctionType WithColor::AutoDetectFunction =
+ 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.
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.");
}
WithColor::warning() << Info.message() << '\n';
});
}
+
+WithColor::AutoDetectFunctionType WithColor::defaultAutoDetectFunction() {
+ return DefaultAutoDetectFunction;
+}
+
+void WithColor::setAutoDetectFunction(
+ AutoDetectFunctionType NewAutoDetectFunction) {
+ AutoDetectFunction = NewAutoDetectFunction;
+}