diff --git a/include/cling/Utils/Output.h b/include/cling/Utils/Output.h index b4838f9a..59dd4f31 100644 --- a/include/cling/Utils/Output.h +++ b/include/cling/Utils/Output.h @@ -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(); diff --git a/lib/Interpreter/CIFactory.cpp b/lib/Interpreter/CIFactory.cpp index a9775c8a..fd87d7e0 100644 --- a/lib/Interpreter/CIFactory.cpp +++ b/lib/Interpreter/CIFactory.cpp @@ -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. diff --git a/lib/Utils/Output.cpp b/lib/Utils/Output.cpp index 65f909a4..7661fad7 100644 --- a/lib/Utils/Output.cpp +++ b/lib/Utils/Output.cpp @@ -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(outs()).Colors(colorStdout); - static_cast(errs()).Colors(colorStderr); - return colorStdout || colorStderr; - } } }