LLVM 20.0.0git
|
An RAII object that temporarily switches an output stream to a specific color. More...
#include "llvm/Support/WithColor.h"
Public Types | |
using | AutoDetectFunctionType = bool(*)(const raw_ostream &OS) |
Public Member Functions | |
LLVM_CTOR_NODISCARD | WithColor (raw_ostream &OS, HighlightColor S, ColorMode Mode=ColorMode::Auto) |
To be used like this: WithColor(OS, HighlightColor::String) << "text";. | |
LLVM_CTOR_NODISCARD | WithColor (raw_ostream &OS, raw_ostream::Colors Color=raw_ostream::SAVEDCOLOR, bool Bold=false, bool BG=false, ColorMode Mode=ColorMode::Auto) |
To be used like this: WithColor(OS, raw_ostream::BLACK) << "text";. | |
~WithColor () | |
raw_ostream & | get () |
operator raw_ostream & () | |
template<typename T > | |
WithColor & | operator<< (T &O) |
template<typename T > | |
WithColor & | operator<< (const T &O) |
bool | colorsEnabled () |
Determine whether colors are displayed. | |
WithColor & | changeColor (raw_ostream::Colors Color, bool Bold=false, bool BG=false) |
Change the color of text that will be output from this point forward. | |
WithColor & | resetColor () |
Reset the colors to terminal defaults. | |
Static Public Member Functions | |
static raw_ostream & | error () |
Convenience method for printing "error: " to stderr. | |
static raw_ostream & | warning () |
Convenience method for printing "warning: " to stderr. | |
static raw_ostream & | note () |
Convenience method for printing "note: " to stderr. | |
static raw_ostream & | remark () |
Convenience method for printing "remark: " to stderr. | |
static raw_ostream & | error (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false) |
Convenience method for printing "error: " to the given stream. | |
static raw_ostream & | warning (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false) |
Convenience method for printing "warning: " to the given stream. | |
static raw_ostream & | note (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false) |
Convenience method for printing "note: " to the given stream. | |
static raw_ostream & | remark (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false) |
Convenience method for printing "remark: " to the given stream. | |
static void | defaultErrorHandler (Error Err) |
Implement default handling for Error. | |
static void | defaultWarningHandler (Error Warning) |
Implement default handling for Warning. | |
static AutoDetectFunctionType | defaultAutoDetectFunction () |
Retrieve the default color auto detection function. | |
static void | setAutoDetectFunction (AutoDetectFunctionType NewAutoDetectFunction) |
Change the global auto detection function. | |
An RAII object that temporarily switches an output stream to a specific color.
Definition at line 54 of file WithColor.h.
using llvm::WithColor::AutoDetectFunctionType = bool (*)(const raw_ostream &OS) |
Definition at line 56 of file WithColor.h.
WithColor::WithColor | ( | raw_ostream & | OS, |
HighlightColor | S, | ||
ColorMode | Mode = ColorMode::Auto |
||
) |
To be used like this: WithColor(OS, HighlightColor::String) << "text";.
OS | The output stream |
S | Symbolic name for syntax element to color |
Mode | Enable, disable or compute whether to use colors. |
Definition at line 44 of file WithColor.cpp.
References llvm::Address, llvm::Attribute, llvm::raw_ostream::BLACK, llvm::raw_ostream::BLUE, llvm::raw_ostream::changeColor(), colorsEnabled(), llvm::raw_ostream::CYAN, llvm::Enumerator, llvm::Error, llvm::raw_ostream::GREEN, llvm::Macro, llvm::raw_ostream::MAGENTA, llvm::Note, OS, llvm::raw_ostream::RED, llvm::Remark, llvm::String, llvm::Tag, llvm::Warning, and llvm::raw_ostream::YELLOW.
|
inline |
To be used like this: WithColor(OS, raw_ostream::BLACK) << "text";.
OS | The output stream |
Color | ANSI color to use, the special SAVEDCOLOR can be used to change only the bold attribute, and keep colors untouched |
Bold | Bold/brighter text, default false |
BG | If true, change the background, default: change foreground |
Mode | Enable, disable or compute whether to use colors. |
Definition at line 71 of file WithColor.h.
References changeColor(), and OS.
WithColor::~WithColor | ( | ) |
Definition at line 156 of file WithColor.cpp.
References resetColor().
WithColor & WithColor::changeColor | ( | raw_ostream::Colors | Color, |
bool | Bold = false , |
||
bool | BG = false |
||
) |
Change the color of text that will be output from this point forward.
Color | ANSI color to use, the special SAVEDCOLOR can be used to change only the bold attribute, and keep colors untouched |
Bold | Bold/brighter text, default false |
BG | If true, change the background, default: change foreground |
Definition at line 143 of file WithColor.cpp.
References llvm::raw_ostream::changeColor(), and colorsEnabled().
Referenced by WithColor().
bool WithColor::colorsEnabled | ( | ) |
Determine whether colors are displayed.
Definition at line 131 of file WithColor.cpp.
References llvm::Auto, llvm::Disable, llvm::Enable, and llvm_unreachable.
Referenced by changeColor(), resetColor(), and WithColor().
|
static |
Retrieve the default color auto detection function.
Definition at line 170 of file WithColor.cpp.
References DefaultAutoDetectFunction().
|
static |
Implement default handling for Error.
Print "error: " to stderr.
Definition at line 158 of file WithColor.cpp.
References error(), llvm::handleAllErrors(), and Info.
|
static |
Implement default handling for Warning.
Print "warning: " to stderr.
Definition at line 164 of file WithColor.cpp.
References llvm::handleAllErrors(), Info, llvm::Warning, and warning().
Referenced by sectionOverflowErrorOrWarning().
|
static |
Convenience method for printing "error: " to stderr.
Definition at line 83 of file WithColor.cpp.
References error(), and llvm::errs().
Referenced by defaultErrorHandler(), error(), llvm::SMDiagnostic::print(), llvm::PrintError(), llvm::dwarf_linker::parallel::DependencyTracker::verifyKeepChain(), llvm::verifyKeepChain(), and writeCOFF().
|
static |
Convenience method for printing "error: " to the given stream.
Definition at line 91 of file WithColor.cpp.
References llvm::Auto, llvm::Disable, llvm::Error, get(), and OS.
|
inline |
Definition at line 79 of file WithColor.h.
Referenced by llvm::DWARFDebugMacro::dump(), llvm::DWARFFormValue::dump(), llvm::DWARFDie::dump(), error(), note(), remark(), and warning().
|
static |
Convenience method for printing "note: " to stderr.
Definition at line 87 of file WithColor.cpp.
References llvm::errs(), and note().
Referenced by llvm::mca::initializeUsedResources(), note(), llvm::SMDiagnostic::print(), llvm::PrintNote(), and llvm::cgdata::warn().
|
static |
Convenience method for printing "note: " to the given stream.
Definition at line 111 of file WithColor.cpp.
References llvm::Auto, llvm::Disable, get(), llvm::Note, and OS.
|
inline |
Definition at line 80 of file WithColor.h.
Definition at line 85 of file WithColor.h.
Definition at line 81 of file WithColor.h.
|
static |
Convenience method for printing "remark: " to stderr.
Definition at line 89 of file WithColor.cpp.
References llvm::errs(), and remark().
Referenced by llvm::SMDiagnostic::print(), and remark().
|
static |
Convenience method for printing "remark: " to the given stream.
Definition at line 121 of file WithColor.cpp.
References llvm::Auto, llvm::Disable, get(), OS, and llvm::Remark.
WithColor & WithColor::resetColor | ( | ) |
Reset the colors to terminal defaults.
Call this when you are done outputting colored text, or before program exit.
Definition at line 150 of file WithColor.cpp.
References colorsEnabled(), and llvm::raw_ostream::resetColor().
Referenced by ~WithColor().
|
static |
Change the global auto detection function.
Definition at line 174 of file WithColor.cpp.
|
static |
Convenience method for printing "warning: " to stderr.
Definition at line 85 of file WithColor.cpp.
References llvm::errs(), and warning().
Referenced by llvm::TargetPassConfig::addMachinePasses(), defaultWarningHandler(), llvm::getHeaders(), llvm::mca::initializeUsedResources(), llvm::SMDiagnostic::print(), llvm::PrintWarning(), llvm::pruneCache(), llvm::reportInvalidSizeRequest(), llvm::cgdata::warn(), and warning().
|
static |
Convenience method for printing "warning: " to the given stream.
Definition at line 101 of file WithColor.cpp.
References llvm::Auto, llvm::Disable, get(), OS, and llvm::Warning.