OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
WTerminalColor Class Reference

Helper class to provide a convenient way to colorize output on the console. More...

#include <WTerminalColor.h>

+ Collaboration diagram for WTerminalColor:

Public Types

enum  TerminalColorAttribute {
  Off = 0 , Bold = 1 , Underscore = 4 , Blink = 5 ,
  Reverse = 7 , Concealed = 8 , Default = 9
}
 Define possible attributes. More...
 
enum  TerminalColorForeground {
  FGBlack = 30 , FGRed = 31 , FGGreen = 32 , FGYellow = 33 ,
  FGBlue = 34 , FGMagenta = 35 , FGCyan = 36 , FGWhite = 37
}
 Foreground colors. More...
 
enum  TerminalColorBackground {
  BGNone = 50 , BGBlack = 40 , BGRed = 41 , BGGreen = 42 ,
  BGYellow = 43 , BGBlue = 44 , BGMagenta = 45 , BGCyan = 46 ,
  BGWhite = 47
}
 Background colors. More...
 

Public Member Functions

 WTerminalColor ()
 Constructor to create a color code which actually does not do any coloring. More...
 
 WTerminalColor (TerminalColorAttribute attrib, TerminalColorForeground foreground, TerminalColorBackground background=BGNone)
 Creates a new terminal color. More...
 
virtual ~WTerminalColor ()
 Destructor. More...
 
std::ostream & operator<< (std::ostream &ostr) const
 Gives the control string which actually enables the color. More...
 
std::string operator() () const
 Gives the control string which actually enables the color. More...
 
std::string operator() (const std::string s) const
 Colorizes the given string and resets color after it. More...
 
std::string operator+ (const std::string &istr) const
 Combines strings. More...
 
std::string operator! () const
 Resets the color and returns control string. More...
 
void setEnabled (bool enabled)
 With this you can easily trigger whether the color control string is used or if "" is returned. More...
 
bool isEnabled () const
 Is coloring enabled? More...
 

Protected Attributes

std::string m_colorString
 The string actually containing the control sequence to enable colors on the console. More...
 
std::string m_colorResetString
 Control sequence to reset color. More...
 
TerminalColorAttribute m_attrib
 Color attributes. More...
 
TerminalColorForeground m_foreground
 The foreground color. More...
 
TerminalColorBackground m_background
 The background color. More...
 

Private Member Functions

void generateControlStrings ()
 Actually generates the control sequences. More...
 

Private Attributes

bool m_enabled
 True when colors should are used. More...
 

Friends

class WTerminalColorTest
 Acess for the test class. More...
 

Detailed Description

Helper class to provide a convenient way to colorize output on the console.

Definition at line 34 of file WTerminalColor.h.

Member Enumeration Documentation

◆ TerminalColorAttribute

Define possible attributes.

Definition at line 44 of file WTerminalColor.h.

◆ TerminalColorBackground

Background colors.

Definition at line 73 of file WTerminalColor.h.

◆ TerminalColorForeground

Foreground colors.

Definition at line 58 of file WTerminalColor.h.

Constructor & Destructor Documentation

◆ WTerminalColor() [1/2]

WTerminalColor::WTerminalColor ( )

Constructor to create a color code which actually does not do any coloring.

Definition at line 31 of file WTerminalColor.cpp.

References generateControlStrings(), m_colorResetString, and m_colorString.

+ Here is the call graph for this function:

◆ WTerminalColor() [2/2]

WTerminalColor::WTerminalColor ( TerminalColorAttribute  attrib,
TerminalColorForeground  foreground,
TerminalColorBackground  background = BGNone 
)

Creates a new terminal color.

Parameters
attribattribute, like bold or blink
foregroundforeground color
backgroundbackground color

Definition at line 43 of file WTerminalColor.cpp.

References generateControlStrings(), m_colorResetString, and m_colorString.

+ Here is the call graph for this function:

◆ ~WTerminalColor()

WTerminalColor::~WTerminalColor ( )
virtual

Destructor.

Definition at line 55 of file WTerminalColor.cpp.

Member Function Documentation

◆ generateControlStrings()

void WTerminalColor::generateControlStrings ( )
private

Actually generates the control sequences.

Definition at line 60 of file WTerminalColor.cpp.

References m_attrib, m_background, m_colorResetString, m_colorString, m_enabled, and m_foreground.

Referenced by setEnabled(), and WTerminalColor().

+ Here is the caller graph for this function:

◆ isEnabled()

bool WTerminalColor::isEnabled ( ) const

Is coloring enabled?

Returns
true if enabled

Definition at line 120 of file WTerminalColor.cpp.

References m_enabled.

◆ operator!()

std::string WTerminalColor::operator! ( ) const

Resets the color and returns control string.

Returns
the control string which resets color settings.

Definition at line 98 of file WTerminalColor.cpp.

References m_colorResetString.

◆ operator()() [1/2]

std::string WTerminalColor::operator() ( ) const

Gives the control string which actually enables the color.

Returns
the color control string

Definition at line 103 of file WTerminalColor.cpp.

References m_colorString.

◆ operator()() [2/2]

std::string WTerminalColor::operator() ( const std::string  s) const

Colorizes the given string and resets color after it.

Parameters
sthe string to colorize
Returns
the string including control sequences.

Definition at line 125 of file WTerminalColor.cpp.

References m_colorResetString, and m_colorString.

◆ operator+()

std::string WTerminalColor::operator+ ( const std::string &  istr) const

Combines strings.

Parameters
istrthe string to combine
Returns
the concatenated string.

Definition at line 108 of file WTerminalColor.cpp.

References m_colorString.

◆ operator<<()

std::ostream & WTerminalColor::operator<< ( std::ostream &  ostr) const

Gives the control string which actually enables the color.

Parameters
ostrthe stream to extend by the color code.
Returns
the color control string

Definition at line 93 of file WTerminalColor.cpp.

References m_colorString.

◆ setEnabled()

void WTerminalColor::setEnabled ( bool  enabled)

With this you can easily trigger whether the color control string is used or if "" is returned.

Parameters
enabledtrue to have colors.

Definition at line 113 of file WTerminalColor.cpp.

References generateControlStrings(), and m_enabled.

Referenced by WLogEntry::getLogString(), and WTerminalColorTest::testColorDisabled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WTerminalColorTest

friend class WTerminalColorTest
friend

Acess for the test class.

Definition at line 39 of file WTerminalColor.h.

Member Data Documentation

◆ m_attrib

TerminalColorAttribute WTerminalColor::m_attrib
protected

Color attributes.

Definition at line 174 of file WTerminalColor.h.

Referenced by generateControlStrings().

◆ m_background

TerminalColorBackground WTerminalColor::m_background
protected

The background color.

Definition at line 184 of file WTerminalColor.h.

Referenced by generateControlStrings().

◆ m_colorResetString

std::string WTerminalColor::m_colorResetString
protected

◆ m_colorString

std::string WTerminalColor::m_colorString
protected

The string actually containing the control sequence to enable colors on the console.

Definition at line 164 of file WTerminalColor.h.

Referenced by generateControlStrings(), operator()(), operator+(), operator<<(), WTerminalColorTest::testColorControlString(), WTerminalColorTest::testColorDisabled(), and WTerminalColor().

◆ m_enabled

bool WTerminalColor::m_enabled
private

True when colors should are used.

Definition at line 195 of file WTerminalColor.h.

Referenced by generateControlStrings(), isEnabled(), and setEnabled().

◆ m_foreground

TerminalColorForeground WTerminalColor::m_foreground
protected

The foreground color.

Definition at line 179 of file WTerminalColor.h.

Referenced by generateControlStrings().


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