LLVM  10.0.0svn
Public Member Functions | Static Public Member Functions | List of all members
llvm::WithColor Class Reference

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

#include "llvm/Support/WithColor.h"

Public Member Functions

 WithColor (raw_ostream &OS, HighlightColor S, bool DisableColors=false)
 To be used like this: WithColor(OS, HighlightColor::String) << "text";. More...
 
 WithColor (raw_ostream &OS, raw_ostream::Colors Color=raw_ostream::SAVEDCOLOR, bool Bold=false, bool BG=false, bool DisableColors=false)
 To be used like this: WithColor(OS, raw_ostream::Black) << "text";. More...
 
 ~WithColor ()
 
raw_ostreamget ()
 
 operator raw_ostream & ()
 
template<typename T >
WithColoroperator<< (T &O)
 
template<typename T >
WithColoroperator<< (const T &O)
 
bool colorsEnabled ()
 Determine whether colors are displayed. More...
 
WithColorchangeColor (raw_ostream::Colors Color, bool Bold=false, bool BG=false)
 Change the color of text that will be output from this point forward. More...
 
WithColorresetColor ()
 Reset the colors to terminal defaults. More...
 

Static Public Member Functions

static raw_ostreamerror ()
 Convenience method for printing "error: " to stderr. More...
 
static raw_ostreamwarning ()
 Convenience method for printing "warning: " to stderr. More...
 
static raw_ostreamnote ()
 Convenience method for printing "note: " to stderr. More...
 
static raw_ostreamremark ()
 Convenience method for printing "remark: " to stderr. More...
 
static raw_ostreamerror (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "error: " to the given stream. More...
 
static raw_ostreamwarning (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "warning: " to the given stream. More...
 
static raw_ostreamnote (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "note: " to the given stream. More...
 
static raw_ostreamremark (raw_ostream &OS, StringRef Prefix="", bool DisableColors=false)
 Convenience method for printing "remark: " to the given stream. More...
 

Detailed Description

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

Definition at line 37 of file WithColor.h.

Constructor & Destructor Documentation

◆ WithColor() [1/2]

WithColor::WithColor ( raw_ostream OS,
HighlightColor  S,
bool  DisableColors = false 
)

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

Parameters
OSThe output stream
SSymbolic name for syntax element to color
DisableColorsWhether to ignore color changes regardless of -color and support in OS

Definition at line 21 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, llvm::raw_ostream::RED, llvm::Remark, llvm::String, llvm::Tag, llvm::Warning, and llvm::raw_ostream::YELLOW.

Referenced by error(), note(), remark(), and warning().

◆ WithColor() [2/2]

llvm::WithColor::WithColor ( raw_ostream OS,
raw_ostream::Colors  Color = raw_ostream::SAVEDCOLOR,
bool  Bold = false,
bool  BG = false,
bool  DisableColors = false 
)
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
DisableColorsWhether to ignore color changes regardless of -color and support in OS

Definition at line 56 of file WithColor.h.

◆ ~WithColor()

WithColor::~WithColor ( )

Definition at line 120 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 107 of file WithColor.cpp.

References llvm::raw_ostream::changeColor(), and colorsEnabled().

◆ colorsEnabled()

bool WithColor::colorsEnabled ( )

Determine whether colors are displayed.

Definition at line 99 of file WithColor.cpp.

References llvm::cl::BOU_TRUE, llvm::cl::BOU_UNSET, llvm::raw_ostream::has_colors(), and UseColor.

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

◆ 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 68 of file WithColor.cpp.

References llvm::StringRef::empty(), llvm::Error, and WithColor().

◆ get()

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

Definition at line 64 of file WithColor.h.

Referenced by llvm::DWARFFormValue::dump(), and llvm::DWARFDie::dump().

◆ note() [1/2]

raw_ostream & WithColor::note ( )
static

Convenience method for printing "note: " to stderr.

Definition at line 64 of file WithColor.cpp.

References llvm::errs().

Referenced by llvm::DWARFVerifier::handleAccelTables(), llvm::mca::initializeUsedResources(), llvm::SMDiagnostic::print(), and llvm::mca::verifyOperands().

◆ 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 84 of file WithColor.cpp.

References llvm::StringRef::empty(), llvm::Note, and WithColor().

◆ operator raw_ostream &()

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

Definition at line 65 of file WithColor.h.

◆ operator<<() [1/2]

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

Definition at line 66 of file WithColor.h.

References llvm::RISCVFenceField::O.

◆ operator<<() [2/2]

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

Definition at line 70 of file WithColor.h.

References error, llvm::RISCVFenceField::O, llvm::cl::Prefix, and warning.

◆ remark() [1/2]

raw_ostream & WithColor::remark ( )
static

Convenience method for printing "remark: " to stderr.

Definition at line 66 of file WithColor.cpp.

References llvm::errs().

Referenced by llvm::SMDiagnostic::print().

◆ 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 91 of file WithColor.cpp.

References llvm::StringRef::empty(), 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 114 of file WithColor.cpp.

References colorsEnabled(), and llvm::raw_ostream::resetColor().

Referenced by ~WithColor().

◆ 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 76 of file WithColor.cpp.

References llvm::StringRef::empty(), llvm::Warning, and WithColor().


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