Second attempt at fixing #34

Fix the issue with the repr of a Python function being used as a prompt.
This commit is contained in:
adam j hartz 2015-03-15 01:44:07 -04:00
parent 42abad5e6d
commit 2e9a8624a8
3 changed files with 11 additions and 9 deletions

View file

@ -54,6 +54,8 @@ class Env(MutableMapping):
return self._detyped
ctx = {}
for key, val in self._d.items():
if callable(val):
continue
if not isinstance(key, string_types):
key = str(key)
if 'PATH' in key:

View file

@ -72,7 +72,7 @@ RE_HIDDEN = re.compile('\001.*?\002')
def multiline_prompt():
"""Returns the filler text for the prompt in multiline scenarios."""
curr = builtins.__xonsh_env__.get('PROMPT', "set '$PROMPT = ...' $ ")
curr = builtins.__xonsh_env__.get('XONSH_PROMPT', "set '$XONSH_PROMPT = ...' $ ")
curr = curr() if callable(curr) else curr
curr = format_prompt(curr)
line = curr.rsplit('\n', 1)[1] if '\n' in curr else curr
@ -83,7 +83,7 @@ def multiline_prompt():
# tail is the trailing whitespace
tail = line if headlen == 0 else line.rsplit(head[-1], 1)[1]
# now to constuct the actual string
dots = builtins.__xonsh_env__.get('MULTILINE_PROMPT', '.')
dots = builtins.__xonsh_env__.get('XONSH_MULTILINE_PROMPT', '.')
dots = dots() if callable(dots) else dots
if dots is None or len(dots) == 0:
return ''
@ -92,8 +92,8 @@ def multiline_prompt():
BASE_ENV = {
'INDENT': ' ',
'PROMPT': default_prompt,
'MULTILINE_PROMPT': '.',
'XONSH_PROMPT': default_prompt,
'XONSH_MULTILINE_PROMPT': '.',
'XONSHRC': os.path.expanduser('~/.xonshrc'),
'XONSH_HISTORY_SIZE': 8128,
'XONSH_HISTORY_FILE': os.path.expanduser('~/.xonsh_history'),

View file

@ -177,13 +177,13 @@ class Shell(Cmd):
self.mlprompt = multiline_prompt()
return self.mlprompt
env = builtins.__xonsh_env__
if 'PROMPT' in env:
p = env['PROMPT']
if 'XONSH_PROMPT' in env:
p = env['XONSH_PROMPT']
if callable(p):
p = p()
else:
p = format_prompt(p)
p = format_prompt(p)
else:
p = "set '$PROMPT = ...' $ "
p = "set '$XONSH_PROMPT = ...' $ "
self.settitle()
env['PROMPT'] = p
return p