OpenWalnut
1.5.0dev
|
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 |
Acess for the test class. More... | |
Helper class to provide a convenient way to colorize output on the console.
Definition at line 34 of file WTerminalColor.h.
Define possible attributes.
Definition at line 44 of file WTerminalColor.h.
Background colors.
Definition at line 73 of file WTerminalColor.h.
Foreground colors.
Definition at line 58 of file WTerminalColor.h.
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.
attrib | attribute, like bold or blink |
foreground | foreground color |
background | background color |
Definition at line 43 of file WTerminalColor.cpp.
References generateControlStrings(), m_colorResetString, and m_colorString.
|
virtual |
Destructor.
Definition at line 55 of file WTerminalColor.cpp.
|
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?
Definition at line 120 of file WTerminalColor.cpp.
References m_enabled.
std::string WTerminalColor::operator! | ( | ) | const |
Resets the color and returns control string.
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.
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.
s | the string to colorize |
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.
istr | the string to combine |
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.
ostr | the stream to extend by the color code. |
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.
enabled | true to have colors. |
Definition at line 113 of file WTerminalColor.cpp.
References generateControlStrings(), and m_enabled.
Referenced by WLogEntry::getLogString(), and WTerminalColorTest::testColorDisabled().
|
friend |
Acess for the test class.
Definition at line 39 of file WTerminalColor.h.
|
protected |
Color attributes.
Definition at line 174 of file WTerminalColor.h.
Referenced by generateControlStrings().
|
protected |
The background color.
Definition at line 184 of file WTerminalColor.h.
Referenced by generateControlStrings().
|
protected |
Control sequence to reset color.
Definition at line 169 of file WTerminalColor.h.
Referenced by generateControlStrings(), operator!(), operator()(), WTerminalColorTest::testColorDisabled(), WTerminalColorTest::testColorResetControlString(), and WTerminalColor().
|
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().
|
private |
True when colors should are used.
Definition at line 195 of file WTerminalColor.h.
Referenced by generateControlStrings(), isEnabled(), and setEnabled().
|
protected |
The foreground color.
Definition at line 179 of file WTerminalColor.h.
Referenced by generateControlStrings().