def _color_text(text, color):
 color_mapping = {u'black': u'0;30', u'red': u'0;31', u'green': u'0;32', u'brown': u'0;33', u'blue': u'0;34', u'magenta': u'0;35', u'cyan': u'0;36', u'lightgrey': u'0;37', u'default': u'0;39', u'darkgrey': u'1;30', u'lightred': u'1;31', u'lightgreen': u'1;32', u'yellow': u'1;33', u'lightblue': u'1;34', u'lightmagenta': u'1;35', u'lightcyan': u'1;36', u'white': u'1;37'}
 if ((sys.platform == u'win32') and (OutStream is None)):
  return text
 color_code = color_mapping.get(color, u'0;39')
 return u'\x1b[{0}m{1}\x1b[0m'.format(color_code, text)

def _color_text ( text , color ) : color_mapping = { u'black' : u'0;30' , u'red' : u'0;31' , u'green' : u'0;32' , u'brown' : u'0;33' , u'blue' : u'0;34' , u'magenta' : u'0;35' , u'cyan' : u'0;36' , u'lightgrey' : u'0;37' , u'default' : u'0;39' , u'darkgrey' : u'1;30' , u'lightred' : u'1;31' , u'lightgreen' : u'1;32' , u'yellow' : u'1;33' , u'lightblue' : u'1;34' , u'lightmagenta' : u'1;35' , u'lightcyan' : u'1;36' , u'white' : u'1;37' } if ( ( sys . platform == u'win32' ) and ( OutStream is None ) ) : return text color_code = color_mapping . get ( color , u'0;39' ) return u'\x1b[{0}m{1}\x1b[0m' . format ( color_code , text )
returns a string wrapped in ansi color codes for coloring the text in a terminal:: colored_text = color_text this wont actually effect the text until it is printed to the terminal .