mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Merge pull request #3155 from xonsh/stderr-pre
fixed XONSH_STDERR_POSTFIX issue
This commit is contained in:
commit
975c07ef15
2 changed files with 44 additions and 9 deletions
24
news/stderr-pre.rst
Normal file
24
news/stderr-pre.rst
Normal 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>
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue