Merge pull request #3155 from xonsh/stderr-pre

fixed XONSH_STDERR_POSTFIX issue
This commit is contained in:
David Strobach 2019-06-06 13:54:05 +02:00 committed by GitHub
commit 975c07ef15
Failed to generate hash of commit
2 changed files with 44 additions and 9 deletions

24
news/stderr-pre.rst Normal file
View file

@ -0,0 +1,24 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fixed issue where setting ``$XONSH_STDERR_PREFIX`` and ``$XONSH_STDERR_POSTFIX``
and running a command in the ``xonshrc`` file would throw an error.
**Security:**
* <news item>

View file

@ -1948,16 +1948,27 @@ def format_std_prepost(template, env=None):
if not template:
return ""
env = builtins.__xonsh__.env if env is None else env
shell = builtins.__xonsh__.shell.shell
try:
s = shell.prompt_formatter(template)
except Exception:
print_exception()
# \001\002 is there to fool pygments into not returning an empty string
# for potentially empty input. This happens when the template is just a
# color code with no visible text.
invis = "\001\002"
s = shell.format_color(invis + s + invis, force_string=True)
if builtins.__xonsh__.shell is None:
# shell hasn't fully started up (probably still in xonshrc)
from xonsh.prompt.base import PromptFormatter
from xonsh.ansi_colors import ansi_partial_color_format
pf = PromptFormatter()
s = pf(template)
style = env.get("XONSH_COLOR_STYLE")
s = ansi_partial_color_format(invis + s + invis, hide=False, style=style)
else:
# shell has fully started. do the normal thing
shell = builtins.__xonsh__.shell.shell
try:
s = shell.prompt_formatter(template)
except Exception:
print_exception()
# \001\002 is there to fool pygments into not returning an empty string
# for potentially empty input. This happens when the template is just a
# color code with no visible text.
s = shell.format_color(invis + s + invis, force_string=True)
s = s.replace(invis, "")
return s