OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends
WTerminalColor Class Reference

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

#include <WTerminalColor.h>

List of all members.

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

Protected Attributes

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

Private Member Functions

void generateControlStrings ()
 Actually generates the control sequences.

Private Attributes

bool m_enabled
 True when colors should are used.

Friends

class WTerminalColorTest

Detailed Description

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

Definition at line 35 of file WTerminalColor.h.


Member Enumeration Documentation

Define possible attributes.

Definition at line 43 of file WTerminalColor.h.

Background colors.

Definition at line 72 of file WTerminalColor.h.

Foreground colors.

Definition at line 57 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 119 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 97 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 102 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 124 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 107 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 92 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 112 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 174 of file WTerminalColor.h.

Referenced by generateControlStrings().

TerminalColorBackground WTerminalColor::m_background
protected

The background color.

Definition at line 184 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 164 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 196 of file WTerminalColor.h.

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

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: