mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
Merge pull request #954 from scopatz/wiz
fixes for wizard in rl shell when storing stdout
This commit is contained in:
commit
42c8c02bc7
2 changed files with 15 additions and 2 deletions
|
@ -156,6 +156,7 @@ class ReadlineShell(BaseShell, Cmd):
|
|||
setup_readline()
|
||||
self._current_indent = ''
|
||||
self._current_prompt = ''
|
||||
self._force_hide = None
|
||||
self.cmdqueue = deque()
|
||||
|
||||
def __del__(self):
|
||||
|
@ -344,8 +345,9 @@ class ReadlineShell(BaseShell, Cmd):
|
|||
p = partial_format_prompt(p)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
print_exception()
|
||||
hide = True if self._force_hide is None else self._force_hide
|
||||
p = partial_color_format(p, style=env.get('XONSH_COLOR_STYLE'),
|
||||
hide=True)
|
||||
hide=hide)
|
||||
self._current_prompt = p
|
||||
self.settitle()
|
||||
return p
|
||||
|
@ -354,6 +356,7 @@ class ReadlineShell(BaseShell, Cmd):
|
|||
"""Readline implementation of color formatting. This usesg ANSI color
|
||||
codes.
|
||||
"""
|
||||
hide = hide if self._force_hide is None else self._force_hide
|
||||
return partial_color_format(string, hide=hide,
|
||||
style=builtins.__xonsh_env__.get('XONSH_COLOR_STYLE'))
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import functools
|
|||
import itertools
|
||||
from pprint import pformat
|
||||
from argparse import ArgumentParser
|
||||
from contextlib import contextmanager
|
||||
|
||||
try:
|
||||
import ply
|
||||
|
@ -288,11 +289,20 @@ def make_wizard(default_file=None, confirm=False):
|
|||
|
||||
def _wizard(ns):
|
||||
env = builtins.__xonsh_env__
|
||||
shell = builtins.__xonsh_shell__.shell
|
||||
fname = env.get('XONSHCONFIG') if ns.file is None else ns.file
|
||||
wiz = make_wizard(default_file=fname, confirm=ns.confirm)
|
||||
tempenv = {'PROMPT': '', 'XONSH_STORE_STDOUT': False}
|
||||
pv = PromptVisitor(wiz, store_in_history=False, multiline=False)
|
||||
with env.swap(tempenv):
|
||||
@contextmanager
|
||||
def force_hide():
|
||||
if env.get('XONSH_STORE_STDOUT') and hasattr(shell, '_force_hide'):
|
||||
orig, shell._force_hide = shell._force_hide, False
|
||||
yield
|
||||
shell._force_hide = orig
|
||||
else:
|
||||
yield
|
||||
with force_hide(), env.swap(tempenv):
|
||||
try:
|
||||
pv.visit()
|
||||
except (KeyboardInterrupt, Exception):
|
||||
|
|
Loading…
Add table
Reference in a new issue