23 #ifndef TermColor20091211H 24 #define TermColor20091211H 29 #include <boost/assign.hpp> 30 #include <boost/foreach.hpp> 31 #include <boost/shared_ptr.hpp> 37 const std::string esc_red =
"\33[31m";
38 const std::string esc_lt_red =
"\33[91m";
39 const std::string esc_green =
"\33[32m";
40 const std::string esc_lt_green =
"\33[92m";
41 const std::string esc_yellow =
"\33[33m";
42 const std::string esc_lt_yellow =
"\33[93m";
43 const std::string esc_blue =
"\33[34m";
44 const std::string esc_lt_blue =
"\33[94m";
45 const std::string esc_magenta =
"\33[35m";
46 const std::string esc_lt_magenta =
"\33[95m";
47 const std::string esc_cyan =
"\33[36m";
48 const std::string esc_lt_cyan =
"\33[96m";
49 const std::string esc_white =
"\33[37m";
50 const std::string esc_lt_white =
"\33[97m";
51 const std::string esc_nocolor =
"\33[0m";
59 std::ostream&
add_escape_code(std::ostream& os,
const std::string& esc_code);
141 return get_instance()->priv_str_from_col(c);
147 return get_instance()->priv_from_esc_code(s);
153 return get_instance()->priv_esc_code_from_col(c);
159 return get_instance()->priv_esc_code_from_str(s);
164 template <
typename T>
friend void boost::checked_delete(T*);
172 static TermColor* get_instance() {
return inst_.get(); }
174 Colors::Color priv_from_str(
const std::string& s) {
return colors_map_[s]; }
179 typedef std::pair<std::string, Colors::Color> P;
180 BOOST_FOREACH (
const P& p, colors_map_)
189 Colors::Color priv_from_esc_code(
const std::string& s) {
return esc_code_map_[s]; }
194 typedef std::pair<std::string, Colors::Color> P;
195 BOOST_FOREACH (
const P& p, esc_code_map_)
204 std::string priv_esc_code_from_str(
const std::string& s)
206 return esc_code_from_col(from_str(s));
210 static boost::shared_ptr<TermColor> inst_;
211 std::map<std::string, Colors::Color> colors_map_;
212 std::map<std::string, Colors::Color> esc_code_map_;
std::ostream & white(std::ostream &os)
All text following this manipulator is white (e.g. std::cout << white << "text";) ...
std::ostream & add_escape_code(std::ostream &os, const std::string &esc_code)
static std::string str_from_col(const Colors::Color &c)
String from color enumeration (e,g, red -> "red")
std::ostream & lt_blue(std::ostream &os)
All text following this manipulator is light blue (e.g. std::cout << lt_blue << "text";) ...
Converts between string, escape code, and enumeration representations of the terminal colors...
std::ostream & lt_red(std::ostream &os)
All text following this manipulator is light red (e.g. std::cout << lt_red << "text";) ...
static Colors::Color from_str(const std::string &s)
Color enumeration from string (e.g. "blue" -> blue)
std::ostream & lt_cyan(std::ostream &os)
All text following this manipulator is light cyan (e.g. std::cout << lt_cyan << "text";) ...
std::ostream & lt_white(std::ostream &os)
All text following this manipulator is bright white (e.g. std::cout << lt_white << "text";) ...
std::ostream & magenta(std::ostream &os)
All text following this manipulator is magenta (e.g. std::cout << magenta << "text";) ...
Color
The eight terminal colors (and bold or "light" variants)
static Colors::Color from_esc_code(const std::string &s)
Color enumeration from escape code (e,g, "\33[31m" -> red)
std::ostream & lt_green(std::ostream &os)
All text following this manipulator is light green (e.g. std::cout << lt_green << "text";) ...
std::ostream & red(std::ostream &os)
All text following this manipulator is red. (e.g. std::cout << red << "text";)
static std::string esc_code_from_str(const std::string &s)
Escape code from string (e.g. "red" -> "\33[31m")
The global namespace for the Goby project.
std::ostream & blue(std::ostream &os)
All text following this manipulator is blue (e.g. std::cout << blue << "text";)
std::ostream & green(std::ostream &os)
All text following this manipulator is green (e.g. std::cout << green << "text";) ...
std::ostream & lt_yellow(std::ostream &os)
All text following this manipulator is light yellow (e.g. std::cout << lt_yellow << "text";) ...
std::ostream & cyan(std::ostream &os)
All text following this manipulator is cyan (e.g. std::cout << cyan << "text";)
Represents the eight available terminal colors (and bold variants)
std::ostream & nocolor(std::ostream &os)
All text following this manipulator is uncolored (e.g. std::cout << green << "green" << nocolor << "u...
static std::string esc_code_from_col(const Colors::Color &c)
Escape code from color enumeration (e.g. red -> "\33[31m")
std::ostream & yellow(std::ostream &os)
All text following this manipulator is yellow (e.g. std::cout << yellow << "text";) ...
std::ostream & lt_magenta(std::ostream &os)
All text following this manipulator is light magenta (e.g. std::cout << lt_magenta << "text";) ...