<s> """<STR_LIT>""" <EOL> from pygments . formatter import Formatter <EOL> from pygments . token import Keyword , Name , Comment , String , Error , Number , Operator , Generic , Token , Whitespace <EOL> from pygments . console import ansiformat <EOL> from pygments . util import get_choice_opt <EOL> __all__ = [ '<STR_LIT>' ] <EOL> TERMINAL_COLORS = { <EOL> Token : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Whitespace : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Comment : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Comment . Preproc : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Keyword : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Keyword . Type : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Operator . Word : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Builtin : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Function : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Namespace : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Class : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Exception : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Decorator : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Variable : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Constant : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Attribute : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Name . Tag : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> String : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Number : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Generic . Deleted : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Generic . Inserted : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Generic . Heading : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Generic . Subheading : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Generic . Error : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Error : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> class TerminalFormatter ( Formatter ) : <EOL> r"""<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> aliases = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> filenames = [ ] <EOL> def __init__ ( self , ** options ) : <EOL> Formatter . __init__ ( self , ** options ) <EOL> self . darkbg = get_choice_opt ( options , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) == '<STR_LIT>' <EOL> self . colorscheme = options . get ( '<STR_LIT>' , None ) or TERMINAL_COLORS <EOL> def format ( self , tokensource , outfile ) : <EOL> enc = self . encoding <EOL> if not enc and hasattr ( outfile , "<STR_LIT>" ) and hasattr ( outfile , "<STR_LIT>" ) and outfile . isatty ( ) : <EOL> enc = outfile . encoding <EOL> for ttype , value in tokensource : <EOL> if enc : <EOL> value = value . encode ( enc ) <EOL> color = self . colorscheme . get ( ttype ) <EOL> while color is None : <EOL> ttype = ttype [ : - <NUM_LIT:1> ] <EOL> color = self . colorscheme . get ( ttype ) <EOL> if color : <EOL> color = color [ self . darkbg ] <EOL> spl = value . split ( '<STR_LIT:\n>' ) <EOL> for line in spl [ : - <NUM_LIT:1> ] : <EOL> if line : <EOL> outfile . write ( ansiformat ( color , line ) ) <EOL> outfile . write ( '<STR_LIT:\n>' ) <EOL> if spl [ - <NUM_LIT:1> ] : <EOL> outfile . write ( ansiformat ( color , spl [ - <NUM_LIT:1> ] ) ) <EOL> else : <EOL> outfile . write ( value ) </s>
