Goby v2
term_color.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #include "term_color.h"
24 #include "flex_ostream.h"
25 
26 // TODO(tes): See if this dynamic cast is unncessary now
27 std::ostream& goby::common::tcolor::add_escape_code(std::ostream& os, const std::string& esc_code)
28 {
29  try
30  {
31  FlexOstream& flex = dynamic_cast<FlexOstream&>(os);
32  return (flex << esc_code);
33  }
34  catch (const std::bad_cast& e)
35  {
36  return (os);
37  }
38 }
39 
40 boost::shared_ptr<goby::common::TermColor> goby::common::TermColor::inst_(new TermColor());
41 
42 goby::common::TermColor::TermColor()
43 {
44  boost::assign::insert(colors_map_)("nocolor", Colors::nocolor)("red", Colors::red)(
45  "lt_red", Colors::lt_red)("green", Colors::green)("lt_green", Colors::lt_green)(
46  "yellow", Colors::yellow)("lt_yellow", Colors::lt_yellow)("blue", Colors::blue)(
47  "lt_blue", Colors::lt_blue)("magenta", Colors::magenta)("lt_magenta", Colors::lt_magenta)(
48  "cyan", Colors::cyan)("lt_cyan", Colors::lt_cyan)("white", Colors::white)("lt_white",
49  Colors::lt_white);
50 
51  boost::assign::insert(esc_code_map_)(esc_nocolor, Colors::nocolor)(esc_red, Colors::red)(
52  esc_lt_red, Colors::lt_red)(esc_green, Colors::green)(esc_lt_green, Colors::lt_green)(
53  esc_yellow, Colors::yellow)(esc_lt_yellow, Colors::lt_yellow)(esc_blue, Colors::blue)(
54  esc_lt_blue, Colors::lt_blue)(esc_magenta, Colors::magenta)(
55  esc_lt_magenta, Colors::lt_magenta)(esc_cyan, Colors::cyan)(esc_lt_cyan, Colors::lt_cyan)(
56  esc_white, Colors::white)(esc_lt_white, Colors::lt_white);
57 }
std::ostream & add_escape_code(std::ostream &os, const std::string &esc_code)
Definition: term_color.cpp:27
Forms the basis of the Goby logger: std::ostream derived class for holding the FlexOStreamBuf.
Definition: flex_ostream.h:43
Converts between string, escape code, and enumeration representations of the terminal colors...
Definition: term_color.h:132