<s> __all__ = [ '<STR_LIT>' ] <EOL> import sys <EOL> styles = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> class Console : <EOL> def __init__ ( self , output = None , styles = [ ] ) : <EOL> output = output or sys . stdout <EOL> if isinstance ( output , Console ) : <EOL> self . output = output . output <EOL> self . styles = output . styles + styles <EOL> else : <EOL> self . output = output <EOL> self . styles = styles <EOL> assert not isinstance ( self . output , Console ) <EOL> def __getattr__ ( self , name ) : <EOL> if name in styles : <EOL> return self . ansi ( name ) <EOL> else : <EOL> raise AttributeError ( name ) <EOL> def ansi ( self , code ) : <EOL> return self . __class__ ( self . output , self . styles + [ code ] ) if code not in ( None , '<STR_LIT>' ) else self <EOL> def __call__ ( self , s ) : <EOL> self . write ( s ) <EOL> def write ( self , s ) : <EOL> self . output . write ( s ) <EOL> def flush ( self , * args ) : <EOL> self . output . flush ( * args ) </s>
