xonsh/tests/prompt/test_job.py
Peter Ye 08b302364a
Update terminal title before executing subprocess (#4916)
* Update terminal title before executing subprocess

This eliminates the need to use `pause_call_resume()`, which causes issues
when it sends SIGSTOP to a process that is in the middle of a syscall
(for example, the `swaymsg` command fails when it gets stopped during
a `recv` syscall).

Additionally, this approach is more flexible, as it allows captured
commands and callable aliases to also be updated as expected in the
terminal's title.

* Clear prompt cache in readline shell

* Add type annotation

* Use reset_key() to only reset current_job

* Convert into PromptField class

* Support PromptField with value of None

Allows {current_job:{} | } to work as expected when current_job is a
PromptField.

* Add tests
2022-08-10 09:50:09 +05:30

13 lines
418 B
Python

def test_current_job(xession):
prompts = xession.env["PROMPT_FIELDS"]
cmds = (["echo", "hello"], "|", ["grep", "h"])
prompts.reset()
assert format(prompts.pick("current_job")) == ""
with prompts["current_job"].update_current_cmds(cmds):
prompts.reset()
assert format(prompts.pick("current_job")) == "grep"
prompts.reset()
assert format(prompts.pick("current_job")) == ""