colorTable.cpp
scratch/src/colorTable.cpp · 3.0 KB
From the archive scratch.tgz
Download the archive « Back to the archive contents
///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
///////////////////// A MUD Server ////////////////////
///////////////////// By: Jared Devall ////////////////////
///////////////////// Thanks: ////////////////////
///////////////////// DIKU/Merc/ROM ////////////////////
///////////////////// Aetas/Deus Gang ////////////////////
///////////////////// Beej ////////////////////
///////////////////////////////////////////////////////////
#include "colorTable.h"
using namespace std;
ColorTable ColorTable::_instance;
const char ColorTable::COLOR_ESCAPE = '{';
const char ColorTable::COLOR_CLEAR = 'x';
ColorTable::ColorTable( ) {
const char ESCAPE_STRING[] = {COLOR_ESCAPE, '\0'};
_colormap.insert( make_pair( COLOR_ESCAPE, string( ESCAPE_STRING ) ) ); // COLOR_ESCAPE
_colormap.insert( make_pair( COLOR_CLEAR, string( "\033[0;0m" ) ) ); // Clear
_colormap.insert( make_pair( '\n', string( "\n" ) ) ); // Newline -- no effect
_colormap.insert( make_pair( 'W', string( "\033[1;37m" ) ) ); // Bright White
_colormap.insert( make_pair( 'k', string( "\033[1;30m" ) ) ); // Gray
_colormap.insert( make_pair( 'b', string( "\033[34m" ) ) ); // Blue
_colormap.insert( make_pair( 'B', string( "\033[1;34m" ) ) ); // Bright Blue
_colormap.insert( make_pair( 'A', string( "\033[44m" ) ) ); // Background Blue
_colormap.insert( make_pair( 'g', string( "\033[32m" ) ) ); // Green
_colormap.insert( make_pair( 'G', string( "\033[1;32m" ) ) ); // Bright Green
_colormap.insert( make_pair( 'E', string( "\033[42m" ) ) ); // Background Green
_colormap.insert( make_pair( 'c', string( "\033[36m" ) ) ); // Cyan
_colormap.insert( make_pair( 'C', string( "\033[1;36m" ) ) ); // Bright Cyan
_colormap.insert( make_pair( 'r', string( "\033[31m" ) ) ); // Red
_colormap.insert( make_pair( 'R', string( "\033[1;31m" ) ) ); // Bright Red
_colormap.insert( make_pair( 'D', string( "\033[41" ) ) ); // Background Red
_colormap.insert( make_pair( 'p', string( "\033[35m" ) ) ); // Purple
_colormap.insert( make_pair( 'P', string( "\033[1;35m" ) ) ); // Bright Purple
_colormap.insert( make_pair( 'y', string( "\033[33m" ) ) ); // Orange
_colormap.insert( make_pair( 'Y', string( "\033[1;33m" ) ) ); // Yellow
_colormap.insert( make_pair( 'a', string( "\033[1;44m" ) ) ); // Bright Background Blue
_colormap.insert( make_pair( 'd', string( "\033[1;41m" ) ) ); // Bright Background Red
_colormap.insert( make_pair( '^', string( "\033[0;1m" ) ) ); // Bold
}
const string &ColorTable::Substitute( char key ) {
static const string empty_string;
ColorMap::iterator it( _instance._colormap.find( key ) );
return it == _instance._colormap.end() ? empty_string : it->second;
}