Support for terminals not using 256 color

As documented in issue #8, the default terminal in OS X 10.6 is xterm-color, which does not support Formatter256Terminal
This commit is contained in:
Mark Larus 2012-02-29 15:21:43 -05:00
parent 1a88ae647e
commit f934f4345e

View File

@ -1,8 +1,10 @@
import json import json
from functools import partial from functools import partial
import pygments import pygments
import os
from pygments.lexers import get_lexer_for_mimetype from pygments.lexers import get_lexer_for_mimetype
from pygments.formatters.terminal256 import Terminal256Formatter from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.formatters.terminal import TerminalFormatter
from pygments.lexer import RegexLexer, bygroups from pygments.lexer import RegexLexer, bygroups
from pygments import token from pygments import token
from . import solarized from . import solarized
@ -23,9 +25,14 @@ class HTTPLexer(RegexLexer):
(r'(.*?:)(.+)', bygroups(token.Name, token.String)) (r'(.*?:)(.+)', bygroups(token.Name, token.String))
]} ]}
if os.environ['TERM'] == 'xterm-256color':
formatter = Terminal256Formatter
else:
formatter = TerminalFormatter
highlight = partial(pygments.highlight, highlight = partial(pygments.highlight,
formatter=Terminal256Formatter( formatter=formatter(
style=solarized.SolarizedStyle)) style=solarized.SolarizedStyle))
highlight_http = partial(highlight, lexer=HTTPLexer()) highlight_http = partial(highlight, lexer=HTTPLexer())