home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2356 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.3 KB  |  84 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from pygments.formatter import Formatter
  5. from pygments.token import Keyword, Name, Comment, String, Error, Number, Operator, Generic, Token, Whitespace
  6. from pygments.console import ansiformat
  7. from pygments.util import get_choice_opt
  8. __all__ = [
  9.     'TerminalFormatter']
  10. TERMINAL_COLORS = {
  11.     Token: ('', ''),
  12.     Whitespace: ('lightgray', 'darkgray'),
  13.     Comment: ('lightgray', 'darkgray'),
  14.     Comment.Preproc: ('teal', 'turquoise'),
  15.     Keyword: ('darkblue', 'blue'),
  16.     Keyword.Type: ('teal', 'turquoise'),
  17.     Operator.Word: ('purple', 'fuchsia'),
  18.     Name.Builtin: ('teal', 'turquoise'),
  19.     Name.Function: ('darkgreen', 'green'),
  20.     Name.Namespace: ('_teal_', '_turquoise_'),
  21.     Name.Class: ('_darkgreen_', '_green_'),
  22.     Name.Exception: ('teal', 'turquoise'),
  23.     Name.Decorator: ('darkgray', 'lightgray'),
  24.     Name.Variable: ('darkred', 'red'),
  25.     Name.Constant: ('darkred', 'red'),
  26.     Name.Attribute: ('teal', 'turquoise'),
  27.     Name.Tag: ('blue', 'blue'),
  28.     String: ('brown', 'brown'),
  29.     Number: ('darkblue', 'blue'),
  30.     Generic.Deleted: ('red', 'red'),
  31.     Generic.Inserted: ('darkgreen', 'green'),
  32.     Generic.Heading: ('**', '**'),
  33.     Generic.Subheading: ('*purple*', '*fuchsia*'),
  34.     Generic.Error: ('red', 'red'),
  35.     Error: ('_red_', '_red_') }
  36.  
  37. class TerminalFormatter(Formatter):
  38.     name = 'Terminal'
  39.     aliases = [
  40.         'terminal',
  41.         'console']
  42.     filenames = []
  43.     
  44.     def __init__(self, **options):
  45.         Formatter.__init__(self, **options)
  46.         self.darkbg = get_choice_opt(options, 'bg', [
  47.             'light',
  48.             'dark'], 'light') == 'dark'
  49.         if not options.get('colorscheme', None):
  50.             pass
  51.         self.colorscheme = TERMINAL_COLORS
  52.  
  53.     
  54.     def format(self, tokensource, outfile):
  55.         if not (self.encoding) and hasattr(outfile, 'encoding') and hasattr(outfile, 'isatty') and outfile.isatty():
  56.             self.encoding = outfile.encoding
  57.         
  58.         return Formatter.format(self, tokensource, outfile)
  59.  
  60.     
  61.     def format_unencoded(self, tokensource, outfile):
  62.         for ttype, value in tokensource:
  63.             color = self.colorscheme.get(ttype)
  64.             while color is None:
  65.                 ttype = ttype[:-1]
  66.                 color = self.colorscheme.get(ttype)
  67.             if color:
  68.                 color = color[self.darkbg]
  69.                 spl = value.split('\n')
  70.                 for line in spl[:-1]:
  71.                     if line:
  72.                         outfile.write(ansiformat(color, line))
  73.                     
  74.                     outfile.write('\n')
  75.                 
  76.                 if spl[-1]:
  77.                     outfile.write(ansiformat(color, spl[-1]))
  78.                 
  79.             spl[-1]
  80.             outfile.write(value)
  81.         
  82.  
  83.  
  84.