ThirdParty/Pygments/pygments/formatters/terminal256.py

changeset 1705
b0fbc9300f2b
parent 684
2f29a0b6e1c7
child 2426
da76c71624de
equal deleted inserted replaced
1704:02ae6c55b35b 1705:b0fbc9300f2b
9 tool (http://frexx.de/xterm-256-notes/data/xterm256-conv2.tar.bz2) 9 tool (http://frexx.de/xterm-256-notes/data/xterm256-conv2.tar.bz2)
10 by Wolfgang Frisch. 10 by Wolfgang Frisch.
11 11
12 Formatter version 1. 12 Formatter version 1.
13 13
14 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. 14 :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
15 :license: BSD, see LICENSE for details. 15 :license: BSD, see LICENSE for details.
16 """ 16 """
17 17
18 # TODO: 18 # TODO:
19 # - Options to map style's bold/underline/italic/border attributes 19 # - Options to map style's bold/underline/italic/border attributes
21 # - An option to output "style RGB to xterm RGB/index" conversion table 21 # - An option to output "style RGB to xterm RGB/index" conversion table
22 # - An option to indicate that we are running in "reverse background" 22 # - An option to indicate that we are running in "reverse background"
23 # xterm. This means that default colors are white-on-black, not 23 # xterm. This means that default colors are white-on-black, not
24 # black-on-while, so colors like "white background" need to be converted 24 # black-on-while, so colors like "white background" need to be converted
25 # to "white background, black foreground", etc... 25 # to "white background, black foreground", etc...
26
27 import sys
26 28
27 from pygments.formatter import Formatter 29 from pygments.formatter import Formatter
28 30
29 31
30 __all__ = ['Terminal256Formatter'] 32 __all__ = ['Terminal256Formatter']
183 185
184 def format(self, tokensource, outfile): 186 def format(self, tokensource, outfile):
185 # hack: if the output is a terminal and has an encoding set, 187 # hack: if the output is a terminal and has an encoding set,
186 # use that to avoid unicode encode problems 188 # use that to avoid unicode encode problems
187 if not self.encoding and hasattr(outfile, "encoding") and \ 189 if not self.encoding and hasattr(outfile, "encoding") and \
188 hasattr(outfile, "isatty") and outfile.isatty(): 190 hasattr(outfile, "isatty") and outfile.isatty() and \
191 sys.version_info < (3,):
189 self.encoding = outfile.encoding 192 self.encoding = outfile.encoding
190 return Formatter.format(self, tokensource, outfile) 193 return Formatter.format(self, tokensource, outfile)
191 194
192 def format_unencoded(self, tokensource, outfile): 195 def format_unencoded(self, tokensource, outfile):
193 for ttype, value in tokensource: 196 for ttype, value in tokensource:

eric ide

mercurial