Skip to content

Commit 980aff3

Browse files
committed
Suspend the toolbar while the editor runs
run_editor() now calls _run_shell_command() directly instead of going through do_shell(), so the suspension on do_shell() no longer covered the editor. Suspend around _run_shell_command(), which both callers share.
1 parent 84ee61f commit 980aff3

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎cmd2/cmd2.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5075,7 +5075,6 @@ def _build_shell_parser(cls) -> Cmd2ArgumentParser:
50755075

50765076
# Preserve quotes since we are passing these strings to the shell
50775077
@with_argparser(_build_shell_parser, preserve_quotes=True)
5078-
@command_toolbar.suspend_toolbar
50795078
def do_shell(self, args: argparse.Namespace) -> None:
50805079
"""Execute a command as if at the OS prompt."""
50815080
# Create a list of arguments to shell
@@ -5085,6 +5084,7 @@ def do_shell(self, args: argparse.Namespace) -> None:
50855084
utils.expand_user_in_tokens(tokens)
50865085
self._run_shell_command(" ".join(tokens))
50875086

5087+
@command_toolbar.suspend_toolbar
50885088
def _run_shell_command(self, command: str) -> None:
50895089
"""Run a command line in the OS shell and wait for it to finish.
50905090

‎tests/test_command_toolbar.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,31 @@ def test_command_toolbar_suspension_and_nested_input(toolbar_app) -> None:
280280
assert toolbar.app.is_running
281281

282282

283+
@pytest.mark.parametrize("launch", ["shell", "editor"])
284+
def test_command_toolbar_suspended_for_shell_and_editor(toolbar_app, launch) -> None:
285+
"""The shell command and the editor both hand the terminal to another program."""
286+
app, _, _ = toolbar_app
287+
app.editor = "vim"
288+
running = []
289+
290+
def popen(*args, **kwargs):
291+
running.append(app._command_toolbar.app.is_running)
292+
return mock.Mock(returncode=0)
293+
294+
with (
295+
mock.patch("subprocess.Popen", side_effect=popen),
296+
mock.patch("cmd2.utils.ProcReader"),
297+
app._command_toolbar_context(),
298+
):
299+
if launch == "shell":
300+
app.do_shell("ls")
301+
else:
302+
app.run_editor("notes.txt")
303+
assert app._command_toolbar.app.is_running
304+
305+
assert running == [False]
306+
307+
283308
class CprOutput(RecordingOutput):
284309
"""A terminal that asks for cursor position reports and never answers them."""
285310

0 commit comments

Comments
 (0)