[lldb] Print diagnostic prefixes (error, warning) in color

Print diagnostic prefixes (error, warning) in their respective colors
when colors are enabled.
This commit is contained in:
Jonas Devlieghere 2022-04-12 20:26:37 -07:00
parent 12e137ab24
commit 990d0c7109
No known key found for this signature in database
GPG Key ID: 49CC0BD90FDEED4D
4 changed files with 13 additions and 6 deletions

View File

@ -20,7 +20,7 @@ class Debugger;
class StreamAsynchronousIO : public Stream {
public:
StreamAsynchronousIO(Debugger &debugger, bool for_stdout);
StreamAsynchronousIO(Debugger &debugger, bool for_stdout, bool colors);
~StreamAsynchronousIO() override;

View File

@ -1201,11 +1201,11 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
}
StreamSP Debugger::GetAsyncOutputStream() {
return std::make_shared<StreamAsynchronousIO>(*this, true);
return std::make_shared<StreamAsynchronousIO>(*this, true, GetUseColor());
}
StreamSP Debugger::GetAsyncErrorStream() {
return std::make_shared<StreamAsynchronousIO>(*this, false);
return std::make_shared<StreamAsynchronousIO>(*this, false, GetUseColor());
}
size_t Debugger::GetNumDebuggers() {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Core/DebuggerEvents.h"
#include "llvm/Support/WithColor.h"
using namespace lldb_private;
@ -56,7 +57,12 @@ llvm::StringRef DiagnosticEventData::GetPrefix() const {
}
void DiagnosticEventData::Dump(Stream *s) const {
*s << GetPrefix() << ": " << GetMessage() << '\n';
llvm::HighlightColor color = m_type == Type::Warning
? llvm::HighlightColor::Warning
: llvm::HighlightColor::Error;
llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)
<< GetPrefix();
*s << ": " << GetMessage() << '\n';
s->Flush();
}

View File

@ -14,8 +14,9 @@
using namespace lldb;
using namespace lldb_private;
StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
: Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
bool colors)
: Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
m_for_stdout(for_stdout) {}
StreamAsynchronousIO::~StreamAsynchronousIO() {