OpenWalnut  1.4.0
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>

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
 

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

Define possible attributes.

Definition at line 41 of file WTerminalColor.h.

Background colors.

Definition at line 70 of file WTerminalColor.h.

Foreground colors.

Definition at line 55 of file WTerminalColor.h.

Constructor & Destructor Documentation

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.

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.

WTerminalColor::~WTerminalColor ( )
virtual

Destructor.

Definition at line 55 of file WTerminalColor.cpp.

Member Function Documentation

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

bool WTerminalColor::isEnabled ( ) const

Is coloring enabled?

Returns
true if enabled

Definition at line 120 of file WTerminalColor.cpp.

References m_enabled.

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.

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.

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.

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.

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.

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

Member Data Documentation

TerminalColorAttribute WTerminalColor::m_attrib
protected

Color attributes.

Definition at line 171 of file WTerminalColor.h.

Referenced by generateControlStrings().

TerminalColorBackground WTerminalColor::m_background
protected

The background color.

Definition at line 181 of file WTerminalColor.h.

Referenced by generateControlStrings().

std::string WTerminalColor::m_colorResetString
protected
std::string WTerminalColor::m_colorString
protected

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

Definition at line 161 of file WTerminalColor.h.

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

bool WTerminalColor::m_enabled
private

True when colors should are used.

Definition at line 192 of file WTerminalColor.h.

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

TerminalColorForeground WTerminalColor::m_foreground
protected

The foreground color.

Definition at line 176 of file WTerminalColor.h.

Referenced by generateControlStrings().


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