mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
refactor: removing prompt_ret_code xontrib (#4815)
This commit is contained in:
parent
1e4eb3ade0
commit
93821fb363
2 changed files with 26 additions and 49 deletions
26
news/remove-prompt-ret-code-xontrib.rst
Normal file
26
news/remove-prompt-ret-code-xontrib.rst
Normal file
|
@ -0,0 +1,26 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* xontrib ``prompt_ret_code`` is now removed.
|
||||
Now the default prompt already shows the last-return-code when the previous command fails.
|
||||
Please use the new prompt fields ``last_return_code``, ``last_return_code_if_nonzero`` from
|
||||
the `PR <https://github.com/xonsh/xonsh/pull/4798>`_
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -1,49 +0,0 @@
|
|||
"""Show the return-code of the last command in the prompt.
|
||||
|
||||
Adds {ret_code} prompt field.
|
||||
"""
|
||||
|
||||
from xonsh.built_ins import XSH
|
||||
from xonsh.tools import ON_WINDOWS as _ON_WINDOWS
|
||||
|
||||
|
||||
def _ret_code_color():
|
||||
if XSH.history.rtns:
|
||||
color = "blue" if XSH.history.rtns[-1] == 0 else "red"
|
||||
else:
|
||||
color = "blue"
|
||||
if _ON_WINDOWS:
|
||||
if color == "blue":
|
||||
return "{BOLD_INTENSE_CYAN}"
|
||||
elif color == "red":
|
||||
return "{BOLD_INTENSE_RED}"
|
||||
else:
|
||||
if color == "blue":
|
||||
return "{BOLD_BLUE}"
|
||||
elif color == "red":
|
||||
return "{BOLD_RED}"
|
||||
|
||||
|
||||
def _ret_code():
|
||||
if XSH.history.rtns:
|
||||
return_code = XSH.history.rtns[-1]
|
||||
if return_code != 0:
|
||||
return f"[{return_code}]"
|
||||
return None
|
||||
|
||||
|
||||
def _update():
|
||||
|
||||
env = XSH.env
|
||||
|
||||
env["PROMPT"] = env["PROMPT"].replace(
|
||||
"{prompt_end}{RESET}", "{ret_code_color}{ret_code}{prompt_end}{RESET}"
|
||||
)
|
||||
|
||||
flds = env["PROMPT_FIELDS"]
|
||||
flds["ret_code_color"] = _ret_code_color
|
||||
flds["ret_code"] = _ret_code
|
||||
|
||||
|
||||
# xontrib loads updates context
|
||||
_update()
|
Loading…
Add table
Reference in a new issue