home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from pygments.formatter import Formatter
- from pygments.token import Keyword, Name, Comment, String, Error, Number, Operator, Generic, Token, Whitespace
- from pygments.console import ansiformat
- from pygments.util import get_choice_opt
- __all__ = [
- 'TerminalFormatter']
- TERMINAL_COLORS = {
- Token: ('', ''),
- Whitespace: ('lightgray', 'darkgray'),
- Comment: ('lightgray', 'darkgray'),
- Comment.Preproc: ('teal', 'turquoise'),
- Keyword: ('darkblue', 'blue'),
- Keyword.Type: ('teal', 'turquoise'),
- Operator.Word: ('purple', 'fuchsia'),
- Name.Builtin: ('teal', 'turquoise'),
- Name.Function: ('darkgreen', 'green'),
- Name.Namespace: ('_teal_', '_turquoise_'),
- Name.Class: ('_darkgreen_', '_green_'),
- Name.Exception: ('teal', 'turquoise'),
- Name.Decorator: ('darkgray', 'lightgray'),
- Name.Variable: ('darkred', 'red'),
- Name.Constant: ('darkred', 'red'),
- Name.Attribute: ('teal', 'turquoise'),
- Name.Tag: ('blue', 'blue'),
- String: ('brown', 'brown'),
- Number: ('darkblue', 'blue'),
- Generic.Deleted: ('red', 'red'),
- Generic.Inserted: ('darkgreen', 'green'),
- Generic.Heading: ('**', '**'),
- Generic.Subheading: ('*purple*', '*fuchsia*'),
- Generic.Error: ('red', 'red'),
- Error: ('_red_', '_red_') }
-
- class TerminalFormatter(Formatter):
- name = 'Terminal'
- aliases = [
- 'terminal',
- 'console']
- filenames = []
-
- def __init__(self, **options):
- Formatter.__init__(self, **options)
- self.darkbg = get_choice_opt(options, 'bg', [
- 'light',
- 'dark'], 'light') == 'dark'
- if not options.get('colorscheme', None):
- pass
- self.colorscheme = TERMINAL_COLORS
-
-
- def format(self, tokensource, outfile):
- if not (self.encoding) and hasattr(outfile, 'encoding') and hasattr(outfile, 'isatty') and outfile.isatty():
- self.encoding = outfile.encoding
-
- return Formatter.format(self, tokensource, outfile)
-
-
- def format_unencoded(self, tokensource, outfile):
- for ttype, value in tokensource:
- color = self.colorscheme.get(ttype)
- while color is None:
- ttype = ttype[:-1]
- color = self.colorscheme.get(ttype)
- if color:
- color = color[self.darkbg]
- spl = value.split('\n')
- for line in spl[:-1]:
- if line:
- outfile.write(ansiformat(color, line))
-
- outfile.write('\n')
-
- if spl[-1]:
- outfile.write(ansiformat(color, spl[-1]))
-
- spl[-1]
- outfile.write(value)
-
-
-
-