Color handling moved from raw_fd_ostream to raw_ostream.
We do not need the wrapper which did more than needed. See llvm/llvm-project@8744d7f25b
This commit is contained in:
parent
c8c61d7aa9
commit
2a956809bb
@ -16,19 +16,6 @@
|
||||
|
||||
namespace cling {
|
||||
namespace utils {
|
||||
///\brief setup colorization of the output streams below
|
||||
///
|
||||
///\param[in] Which - Ored value of streams to colorize: 0 means none.
|
||||
/// 0 = Don't colorize any output
|
||||
/// 1 = Colorize cling::outs
|
||||
/// 2 = Colorize cling::errs
|
||||
/// 4 = Colorize cling::log (currently always the same as cling::errs)
|
||||
/// 8 = Colorize based on whether stdout/err are dsiplayed on tty or not.
|
||||
///
|
||||
///\returns Whether any output stream was colorized.
|
||||
///
|
||||
bool ColorizeOutput(unsigned Which = 8);
|
||||
|
||||
///\brief The 'stdout' stream. llvm::raw_ostream wrapper of std::cout
|
||||
///
|
||||
llvm::raw_ostream& outs();
|
||||
|
@ -1406,7 +1406,9 @@ namespace {
|
||||
CI->setInvocation(InvocationPtr);
|
||||
CI->setDiagnostics(Diags.get()); // Diags is ref-counted
|
||||
if (!OnlyLex)
|
||||
CI->getDiagnosticOpts().ShowColors = cling::utils::ColorizeOutput();
|
||||
CI->getDiagnosticOpts().ShowColors =
|
||||
llvm::sys::Process::StandardOutIsDisplayed() ||
|
||||
llvm::sys::Process::StandardErrIsDisplayed();
|
||||
|
||||
// Copied from CompilerInstance::createDiagnostics:
|
||||
// Chain in -verify checker, if requested.
|
||||
|
@ -17,75 +17,24 @@
|
||||
|
||||
namespace cling {
|
||||
namespace utils {
|
||||
|
||||
namespace {
|
||||
class ColoredOutput : public llvm::raw_os_ostream {
|
||||
bool m_Colorize = true;
|
||||
|
||||
raw_ostream& changeColor(enum Colors colors, bool bold, bool bg) override {
|
||||
if (m_Colorize) {
|
||||
if (llvm::sys::Process::ColorNeedsFlush()) flush();
|
||||
if (const char* colorcode =
|
||||
(colors == SAVEDCOLOR)
|
||||
? llvm::sys::Process::OutputBold(bg)
|
||||
: llvm::sys::Process::OutputColor(colors, bold, bg))
|
||||
write(colorcode, strlen(colorcode));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
raw_ostream& resetColor() override {
|
||||
if (m_Colorize) {
|
||||
if (llvm::sys::Process::ColorNeedsFlush()) flush();
|
||||
if (const char* colorcode = llvm::sys::Process::ResetColor())
|
||||
write(colorcode, ::strlen(colorcode));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
raw_ostream& reverseColor() override {
|
||||
if (m_Colorize) {
|
||||
if (llvm::sys::Process::ColorNeedsFlush()) flush();
|
||||
|
||||
if (const char* colorcode = llvm::sys::Process::OutputReverse())
|
||||
write(colorcode, ::strlen(colorcode));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
bool has_colors() const override { return m_Colorize; }
|
||||
bool is_displayed() const override { return m_Colorize; }
|
||||
public:
|
||||
|
||||
ColoredOutput(std::ostream& Out, bool Unbufferd = true)
|
||||
: raw_os_ostream(Out) {
|
||||
if (Unbufferd) SetUnbuffered();
|
||||
}
|
||||
|
||||
bool Colors(bool C) { m_Colorize = C; return m_Colorize; }
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
llvm::raw_ostream& outs() {
|
||||
static ColoredOutput sOut(std::cout);
|
||||
static llvm::raw_os_ostream sOut(std::cout);
|
||||
sOut.SetUnbuffered();
|
||||
if (llvm::sys::Process::StandardOutIsDisplayed())
|
||||
sOut.enable_colors(true);
|
||||
return sOut;
|
||||
}
|
||||
|
||||
llvm::raw_ostream& errs() {
|
||||
static ColoredOutput sErr(std::cerr);
|
||||
static llvm::raw_os_ostream sErr(std::cerr);
|
||||
sErr.SetUnbuffered();
|
||||
if (llvm::sys::Process::StandardErrIsDisplayed())
|
||||
sErr.enable_colors(true);
|
||||
return sErr;
|
||||
}
|
||||
|
||||
llvm::raw_ostream& log() {
|
||||
return cling::errs();
|
||||
}
|
||||
|
||||
bool ColorizeOutput(unsigned Which) {
|
||||
#define COLOR_FLAG(Fv, Fn) (Which == 8 ? llvm::sys::Process::Fn() : Which & Fv)
|
||||
bool colorStdout = COLOR_FLAG(1, StandardOutIsDisplayed);
|
||||
bool colorStderr = COLOR_FLAG(2, StandardErrIsDisplayed);
|
||||
// The following calls have side effects because they set m_Colorize!
|
||||
static_cast<ColoredOutput &>(outs()).Colors(colorStdout);
|
||||
static_cast<ColoredOutput &>(errs()).Colors(colorStderr);
|
||||
return colorStdout || colorStderr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user