Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
util/liblogger/term_color.cpp
00001 // copyright 2009 t. schneider tes@mit.edu
00002 //
00003 // this file is part of flex-ostream, a terminal display library
00004 // that provides an ostream with both terminal display and file logging
00005 //
00006 // This program is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This software is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 #include "flex_ostream.h"
00020 #include "term_color.h"
00021 
00022 // TODO(tes): See if this dynamic cast is unncessary now 
00023 std::ostream& goby::util::tcolor::add_escape_code(std::ostream& os, const std::string& esc_code)
00024 {
00025     try
00026     {
00027         FlexOstream& flex = dynamic_cast<FlexOstream&>(os);
00028         return(flex << esc_code);
00029     }
00030     catch (const std::bad_cast& e)
00031     { return(os); }
00032 }
00033 
00034 
00035 goby::util::TermColor* goby::util::TermColor::inst_ = 0;
00036 
00037 goby::util::TermColor* goby::util::TermColor::get_instance()
00038 {
00039     if(!inst_) inst_ = new TermColor();
00040     return(inst_);
00041 }
00042 
00043 goby::util::TermColor::TermColor()
00044 {
00045     boost::assign::insert(colors_map_)
00046         ("nocolor",Colors::nocolor)
00047         ("red",Colors::red)         ("lt_red",Colors::lt_red)
00048         ("green",Colors::green)     ("lt_green",Colors::lt_green)
00049         ("yellow",Colors::yellow)   ("lt_yellow",Colors::lt_yellow)
00050         ("blue",Colors::blue)       ("lt_blue",Colors::lt_blue)
00051         ("magenta",Colors::magenta) ("lt_magenta",Colors::lt_magenta)
00052         ("cyan",Colors::cyan)       ("lt_cyan",Colors::lt_cyan)
00053         ("white",Colors::white)     ("lt_white",Colors::lt_white);
00054 
00055     boost::assign::insert(esc_code_map_)
00056         (esc_nocolor,Colors::nocolor)
00057         (esc_red,Colors::red)         (esc_lt_red,Colors::lt_red)
00058         (esc_green,Colors::green)     (esc_lt_green,Colors::lt_green)
00059         (esc_yellow,Colors::yellow)   (esc_lt_yellow,Colors::lt_yellow)
00060         (esc_blue,Colors::blue)       (esc_lt_blue,Colors::lt_blue)
00061         (esc_magenta,Colors::magenta) (esc_lt_magenta,Colors::lt_magenta)
00062         (esc_cyan,Colors::cyan)       (esc_lt_cyan,Colors::lt_cyan)
00063         (esc_white,Colors::white)     (esc_lt_white,Colors::lt_white);
00064 
00065 }
00066 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends