LLVM 22.0.0git
llvm::WithColor Class Reference

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 LLVM_ABI 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";.
LLVM_ABI ~WithColor ()
raw_ostreamget ()
 operator raw_ostream & ()
template<typename T>
WithColoroperator<< (T &O)
template<typename T>
WithColoroperator<< (const T &O)
LLVM_ABI bool colorsEnabled ()
 Determine whether colors are displayed.
LLVM_ABI WithColorchangeColor (raw_ostream::Colors Color, bool Bold=false, bool BG=false)
 Change the color of text that will be output from this point forward.
LLVM_ABI WithColorresetColor ()
 Reset the colors to terminal defaults.

Static Public Member Functions

static LLVM_ABI raw_ostreamerror ()
 Convenience method for printing "error: " to stderr.
static LLVM_ABI raw_ostreamwarning ()
 Convenience method for printing "warning: " to stderr.
static LLVM_ABI raw_ostreamnote ()
 Convenience method for printing "note: " to stderr.
static LLVM_ABI raw_ostreamremark ()
 Convenience method for printing "remark: " to stderr.
static LLVM_ABI raw_ostreamerror (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "error: " to the given stream.
static LLVM_ABI raw_ostreamwarning (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "warning: " to the given stream.
static LLVM_ABI raw_ostreamnote (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "note: " to the given stream.
static LLVM_ABI raw_ostreamremark (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "remark: " to the given stream.
static LLVM_ABI void defaultErrorHandler (Error Err)
 Implement default handling for Error.
static LLVM_ABI void defaultWarningHandler (Error Warning)
 Implement default handling for Warning.
static LLVM_ABI AutoDetectFunctionType defaultAutoDetectFunction ()
 Retrieve the default color auto detection function.
static LLVM_ABI void setAutoDetectFunction (AutoDetectFunctionType NewAutoDetectFunction)
 Change the global auto detection function.

Detailed Description

An RAII object that temporarily switches an output stream to a specific color.

Definition at line 54 of file WithColor.h.

Member Typedef Documentation

โ—† AutoDetectFunctionType

Definition at line 56 of file WithColor.h.

Constructor & Destructor Documentation

โ—† WithColor() [1/2]

WithColor::WithColor ( raw_ostream & OS,
HighlightColor S,
ColorMode Mode = ColorMode::Auto )

To be used like this: WithColor(OS, HighlightColor::String) << "text";.

Parameters
OSThe output stream
SSymbolic name for syntax element to color
ModeEnable, 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, colorsEnabled(), llvm::raw_ostream::CYAN, llvm::Enumerator, llvm::Error, llvm::raw_ostream::GREEN, llvm::Macro, llvm::raw_ostream::MAGENTA, llvm::Note, llvm::raw_ostream::RED, llvm::Remark, llvm::String, llvm::Tag, llvm::Warning, and llvm::raw_ostream::YELLOW.

Referenced by changeColor(), error(), note(), operator<<(), operator<<(), remark(), resetColor(), and warning().

โ—† WithColor() [2/2]

LLVM_CTOR_NODISCARD llvm::WithColor::WithColor ( raw_ostream & OS,
raw_ostream::Colors Color = raw_ostream::SAVEDCOLOR,
bool Bold = false,
bool BG = false,
ColorMode Mode = ColorMode::Auto )
inline

To be used like this: WithColor(OS, raw_ostream::BLACK) << "text";.

Parameters
OSThe output stream
ColorANSI color to use, the special SAVEDCOLOR can be used to change only the bold attribute, and keep colors untouched
BoldBold/brighter text, default false
BGIf true, change the background, default: change foreground
ModeEnable, disable or compute whether to use colors.

Definition at line 71 of file WithColor.h.

References llvm::Auto, changeColor(), LLVM_CTOR_NODISCARD, and llvm::raw_ostream::SAVEDCOLOR.

โ—† ~WithColor()

WithColor::~WithColor ( )

Definition at line 156 of file WithColor.cpp.

References resetColor().

Member Function Documentation

โ—† changeColor()

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.

Parameters
ColorANSI color to use, the special SAVEDCOLOR can be used to change only the bold attribute, and keep colors untouched
BoldBold/brighter text, default false
BGIf true, change the background, default: change foreground

Definition at line 143 of file WithColor.cpp.

References changeColor(), colorsEnabled(), and WithColor().

Referenced by changeColor(), and WithColor().

โ—† colorsEnabled()

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().

โ—† defaultAutoDetectFunction()

WithColor::AutoDetectFunctionType WithColor::defaultAutoDetectFunction ( )
static

Retrieve the default color auto detection function.

Definition at line 170 of file WithColor.cpp.

References DefaultAutoDetectFunction().

โ—† defaultErrorHandler()

void WithColor::defaultErrorHandler ( Error Err)
static

Implement default handling for Error.

Print "error: " to stderr.

Definition at line 158 of file WithColor.cpp.

References error(), and llvm::handleAllErrors().

Referenced by llvm::DWARFContext::DWARFContextState.

โ—† defaultWarningHandler()

void WithColor::defaultWarningHandler ( Error Warning)
static

Implement default handling for Warning.

Print "warning: " to stderr.

Definition at line 164 of file WithColor.cpp.

References llvm::handleAllErrors(), llvm::Warning, and warning().

Referenced by llvm::DWARFContext::DWARFContextState, and sectionOverflowErrorOrWarning().

โ—† error() [1/2]

raw_ostream & WithColor::error ( )
static

โ—† error() [2/2]

raw_ostream & WithColor::error ( raw_ostream & OS,
StringRef Prefix = "",
bool DisableColors = false )
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, and WithColor().

โ—† get()

raw_ostream & llvm::WithColor::get ( )
inline

โ—† note() [1/2]

raw_ostream & WithColor::note ( )
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(), llvm::PrintNote(), and llvm::cgdata::warn().

โ—† note() [2/2]

raw_ostream & WithColor::note ( raw_ostream & OS,
StringRef Prefix = "",
bool DisableColors = false )
static

Convenience method for printing "note: " to the given stream.

Definition at line 111 of file WithColor.cpp.

References llvm::Auto, llvm::Disable, llvm::Note, and WithColor().

โ—† operator raw_ostream &()

llvm::WithColor::operator raw_ostream & ( )
inline

Definition at line 80 of file WithColor.h.

โ—† operator<<() [1/2]

template<typename T>
WithColor & llvm::WithColor::operator<< ( const T & O)
inline

Definition at line 85 of file WithColor.h.

References T, and WithColor().

โ—† operator<<() [2/2]

template<typename T>
WithColor & llvm::WithColor::operator<< ( T & O)
inline

Definition at line 81 of file WithColor.h.

References T, and WithColor().

โ—† remark() [1/2]

raw_ostream & WithColor::remark ( )
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().

โ—† remark() [2/2]

raw_ostream & WithColor::remark ( raw_ostream & OS,
StringRef Prefix = "",
bool DisableColors = false )
static

Convenience method for printing "remark: " to the given stream.

Definition at line 121 of file WithColor.cpp.

References llvm::Auto, llvm::Disable, llvm::Remark, and WithColor().

โ—† resetColor()

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(), resetColor(), and WithColor().

Referenced by resetColor(), and ~WithColor().

โ—† setAutoDetectFunction()

void WithColor::setAutoDetectFunction ( AutoDetectFunctionType NewAutoDetectFunction)
static

Change the global auto detection function.

Definition at line 174 of file WithColor.cpp.

โ—† warning() [1/2]

raw_ostream & WithColor::warning ( )
static

โ—† warning() [2/2]

raw_ostream & WithColor::warning ( raw_ostream & OS,
StringRef Prefix = "",
bool DisableColors = false )
static

Convenience method for printing "warning: " to the given stream.

Definition at line 101 of file WithColor.cpp.

References llvm::Auto, llvm::Disable, llvm::Warning, and WithColor().


The documentation for this class was generated from the following files: