#include <genesis/utils/text/style.hpp>
Simple text style class for colorized and bold output to a terminal.
This class bundles the following text style properties for output in a terminal:
Those properties can be set using either the respective constructor of this class or using the setter functions. Per default, all of them are empty, meaning that no style manupulation is done.
In order to generate textual output with those styles, operator()() is used. Example:
Style blue( "blue" ); blue.bold( true ); std::cout << blue( "some text" );
Furthermore, the stream operator can be used to get a summary of the properties of a Style object:
LOG_DBG << blue;
will output
Foreground Color: Blue Background Color: Bold: true
to the LOG stream.
Public Member Functions | |
Style ()=default | |
Style (bool bold) | |
Style (const char *foreground_color) | |
Style (std::string const &foreground_color) | |
Style (std::string const &foreground_color, bool bold) | |
Style (std::string const &foreground_color, const char *background_color) | |
Style (std::string const &foreground_color, std::string const &background_color) | |
Style (std::string const &foreground_color, std::string const &background_color, bool bold) | |
Style (Style &&)=default | |
Style (Style const &)=default | |
~Style ()=default | |
std::string | background_color () const |
Style & | background_color (std::string const &color) |
bool | bold () const |
Return whether the Style uses bold. More... | |
Style & | bold (bool value) |
Set whether the Style uses bold. More... | |
bool | enabled () const |
Return whether the Style is currently enabled. More... | |
Style & | enabled (bool value) |
Set whether the Style is enabled. More... | |
std::string | foreground_color () const |
Style & | foreground_color (std::string const &color) |
std::string | operator() (std::string const &text) const |
Operator that returns a text with the current Style applied to it. More... | |
Style & | operator= (Style &&)=default |
Style & | operator= (Style const &)=default |
Style & | reset () |
Reset the Style to use not colors and not bold. More... | |
void | swap (Style &other) |
std::string | to_bash_string (std::string const &text) const |
Additional output function with the same purpose as operator(). More... | |
std::string | to_python_string (std::string const &text) const |
Additional output function with the same purpose as operator(). More... | |
Static Public Member Functions | |
static std::string | get_background_color_value (std::string name) |
Return the color value string for a given background color name. More... | |
static std::string | get_foreground_color_value (std::string name) |
Return the color value string for a given foreground color name. More... | |
static bool | is_background_color (std::string name) |
Return true iff the given name is a background color name. More... | |
static bool | is_foreground_color (std::string name) |
Return true iff the given name is a foreground color name. More... | |
Static Public Attributes | |
static const std::array< std::pair< std::string, std::string >, 17 > | background_colors |
List of all valid background color names and their color strings. More... | |
static const std::array< std::pair< std::string, std::string >, 17 > | foreground_colors |
List of all valid foreground color names and their color strings. More... | |
|
default |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
default |
Style & bold | ( | bool | value | ) |
bool enabled | ( | ) | const |
Style & enabled | ( | bool | value | ) |
|
static |
Return the color value string for a given background color name.
See Style::foreground_colors for background valid color names. If the name is invalid, the function throws an std::out_of_range
exception.
|
static |
Return the color value string for a given foreground color name.
See Style::foreground_colors for valid foreground color names. If the name is invalid, the function throws an std::out_of_range
exception.
|
static |
|
static |
std::string operator() | ( | std::string const & | text | ) | const |
Style & reset | ( | ) |
std::string to_bash_string | ( | std::string const & | text | ) | const |
std::string to_python_string | ( | std::string const & | text | ) | const |
|
static |
List of all valid background color names and their color strings.
|
static |
List of all valid foreground color names and their color strings.