mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
colorize output
This commit is contained in:
parent
2c215b990a
commit
5c82ae5ef1
1 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue