colorize output

This commit is contained in:
Anthony Scopatz 2016-02-18 00:23:36 -05:00
parent 2c215b990a
commit 5c82ae5ef1

View file

@ -13,8 +13,14 @@ except ImportError:
from xonsh import __version__
from xonsh.shell import Shell
from xonsh.pretty import pprint
from xonsh.pretty import pprint, pretty
from xonsh.jobs import ignore_sigtstp
from xonsh.tools import HAVE_PYGMENTS, print_color
if HAVE_PYGMENTS:
import pygments
from xonsh import pyghooks
def path_argument(s):
"""Return a path only if the path is actually legal
@ -123,7 +129,13 @@ def undo_args(args):
def _pprint_displayhook(value):
if value is not None:
builtins._ = None # Set '_' to None to avoid recursion
pprint(value)
if HAVE_PYGMENTS:
s = pretty(value) # color case
lexer = pyghooks.XonshLexer()
tokens = list(pygments.lex(s, lexer=lexer))
print_color(tokens)
else:
pprint(value) # black & white case
builtins._ = value