<s> from __future__ import unicode_literals <EOL> import sys <EOL> from . compat import PY3 , str_ <EOL> FG_BLACK = <NUM_LIT:30> <EOL> FG_RED = <NUM_LIT> <EOL> FG_GREEN = <NUM_LIT:32> <EOL> FG_YELLOW = <NUM_LIT> <EOL> FG_BLUE = <NUM_LIT> <EOL> FG_MAGENTA = <NUM_LIT> <EOL> FG_CYAN = <NUM_LIT> <EOL> FG_WHITE = <NUM_LIT> <EOL> FG_RESET = <NUM_LIT> <EOL> BG_BLACK = <NUM_LIT> <EOL> BG_RED = <NUM_LIT> <EOL> BG_GREEN = <NUM_LIT> <EOL> BG_YELLOW = <NUM_LIT> <EOL> BG_BLUE = <NUM_LIT> <EOL> BG_MAGENTA = <NUM_LIT> <EOL> BG_CYAN = <NUM_LIT> <EOL> BG_WHITE = <NUM_LIT> <EOL> BG_RESET = <NUM_LIT> <EOL> enabled = True <EOL> _enabled = hasattr ( sys . stdout , '<STR_LIT>' ) and sys . stdout . isatty ( ) <EOL> class ColorCombo ( object ) : <EOL> def __init__ ( self , foreground = <NUM_LIT:0> , background = <NUM_LIT:0> , bright = None ) : <EOL> self . foreground = foreground or FG_RESET <EOL> self . background = background or BG_RESET <EOL> self . set_bright ( bright ) <EOL> def set_bright ( self , bright ) : <EOL> if bright is None : <EOL> self . flag = <NUM_LIT> <EOL> elif bright : <EOL> self . flag = <NUM_LIT:1> <EOL> else : <EOL> self . flag = <NUM_LIT:2> <EOL> def copy ( self ) : <EOL> c = ColorCombo ( self . foreground , self . background ) <EOL> c . flag = self . flag <EOL> return c <EOL> def __repr__ ( self ) : <EOL> r = '<STR_LIT>' . format ( self . foreground , self . background ) <EOL> if PY3 : <EOL> return r <EOL> return r . encode ( '<STR_LIT:utf8>' ) <EOL> HEY = ColorCombo ( FG_RED ) <EOL> YAY = ColorCombo ( FG_GREEN ) <EOL> MEH = ColorCombo ( FG_YELLOW ) <EOL> GOOD = ColorCombo ( FG_BLUE ) <EOL> NEAT = ColorCombo ( FG_CYAN ) <EOL> SHHH = ColorCombo ( FG_MAGENTA ) <EOL> NOOO = ColorCombo ( FG_WHITE , BG_RED , bright = True ) <EOL> MAN = ColorCombo ( FG_BLACK , BG_YELLOW , bright = True ) <EOL> class ColorTextRun ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , * items ) : <EOL> self . items = list ( items ) <EOL> def __len__ ( self ) : <EOL> return sum ( map ( len , self . items ) ) <EOL> def __unicode__ ( self ) : <EOL> return str_ ( '<STR_LIT>' . join ( map ( str_ , self . items ) ) ) <EOL> def __str__ ( self ) : <EOL> if PY3 : <EOL> return self . __unicode__ ( ) <EOL> return self . __unicode__ ( ) . encode ( '<STR_LIT:utf8>' ) <EOL> def __repr__ ( self ) : <EOL> r = '<STR_LIT>' . format ( [ repr ( x ) for x in self . items ] ) <EOL> if PY3 : <EOL> return r <EOL> return r . encode ( '<STR_LIT:utf8>' ) <EOL> def __add__ ( self , other ) : <EOL> self . items . append ( other ) <EOL> return self <EOL> def __radd__ ( self , other ) : <EOL> self . items . insert ( <NUM_LIT:0> , other ) <EOL> return self <EOL> def encode ( self , * args , ** kwargs ) : <EOL> return str_ ( self ) . encode ( * args , ** kwargs ) <EOL> def decode ( self , * args , ** kwargs ) : <EOL> return str_ ( self ) . decode ( * args , ** kwargs ) <EOL> class ColorText ( object ) : <EOL> '''<STR_LIT>''' <EOL> fmt = '<STR_LIT>' <EOL> def __init__ ( self , text , foreground = <NUM_LIT:0> , background = <NUM_LIT:0> , ignore_setting = False ) : <EOL> self . text = text <EOL> if isinstance ( foreground , ColorCombo ) : <EOL> self . color = foreground <EOL> else : <EOL> self . color = ColorCombo ( foreground or FG_RESET , <EOL> background or BG_RESET ) <EOL> self . ignore_setting = ignore_setting <EOL> def __len__ ( self ) : <EOL> return len ( self . text ) <EOL> def __unicode__ ( self ) : <EOL> if not _enabled or ( not self . ignore_setting and not enabled ) : <EOL> return self . text <EOL> return self . fmt . format ( fg = self . color . foreground , <EOL> bg = self . color . background , <EOL> f = self . color . flag , <EOL> t = self . text ) <EOL> def __str__ ( self ) : <EOL> if PY3 : <EOL> return str_ ( self . __unicode__ ( ) ) <EOL> return self . __unicode__ ( ) . encode ( '<STR_LIT:utf8>' ) <EOL> def __repr__ ( self ) : <EOL> r = '<STR_LIT>' . format ( self . text , repr ( self . color ) ) <EOL> if PY3 : <EOL> return r <EOL> return r . encode ( '<STR_LIT:utf8>' ) <EOL> def __add__ ( self , other ) : <EOL> return ColorTextRun ( self , other ) <EOL> def __radd__ ( self , other ) : <EOL> return ColorTextRun ( other , self ) <EOL> def encode ( self , * args , ** kwargs ) : <EOL> return str_ ( self ) . encode ( * args , ** kwargs ) <EOL> def decode ( self , * args , ** kwargs ) : <EOL> return str_ ( self ) . decode ( * args , ** kwargs ) </s>
