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

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.

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.

Destructor.

Definition at line 55 of file WTerminalColor.cpp.


Member Function Documentation

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

Color attributes.

Definition at line 171 of file WTerminalColor.h.

Referenced by generateControlStrings().

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

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: