From 3a6e76c1afcb87fa5d4228d146c8c4ffdd76c5d4 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 1 Sep 2026 15:11:13 -0400 Subject: [PATCH] hide timings after "/system clear" Special case "/system clear" to show no timing info. When the user asks to clear the screen, they probably want to clear the screen, not "clear the screen except for timing info". Motivation: this is helpful when making screenshots. --- changelog.md | 1 + mycli/packages/special/iocommands.py | 5 +++-- test/pytests/test_special_iocommands.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index e9a22261c..94bac45ff 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ Upcoming (TBD) Features -------- * Add `/ping` special command. +* Hide timings after `/system clear`. Documentation diff --git a/mycli/packages/special/iocommands.py b/mycli/packages/special/iocommands.py index b6def0485..d9eaf8c29 100644 --- a/mycli/packages/special/iocommands.py +++ b/mycli/packages/special/iocommands.py @@ -787,8 +787,9 @@ def execute_system_command(arg: str, **_) -> list[SQLResult]: completed_process = subprocess.run(command, check=False) if completed_process.returncode: return [SQLResult(status=f'Command exited with return code {completed_process.returncode}')] - else: - return [SQLResult()] + if command[0].lower() == 'clear': + return [] + return [SQLResult()] else: process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: diff --git a/test/pytests/test_special_iocommands.py b/test/pytests/test_special_iocommands.py index ff40736b9..ba29c2723 100644 --- a/test/pytests/test_special_iocommands.py +++ b/test/pytests/test_special_iocommands.py @@ -1491,6 +1491,7 @@ def raise_value_error(*_args, **_kwargs): [ ('-r echo ok', 0, None), ('vim file.sql', 1, 'Command exited with return code 1'), + ('clear', 1, 'Command exited with return code 1'), ], ) def test_execute_system_command_raw_modes( @@ -1512,6 +1513,20 @@ def fake_run(cmd: list[str], check: bool = False) -> SimpleNamespace: assert result.status == expected_status +@pytest.mark.parametrize('command', ['clear', 'CLEAR', '-r clear']) +def test_execute_system_clear_returns_no_result(monkeypatch, command: str) -> None: + calls: list[list[str]] = [] + + def fake_run(cmd: list[str], check: bool = False) -> SimpleNamespace: + calls.append(cmd) + return SimpleNamespace(returncode=0) + + monkeypatch.setattr(iocommands.subprocess, 'run', fake_run) + + assert iocommands.execute_system_command(command) == [] + assert calls == [[part for part in command.split() if part != '-r']] + + def test_execute_system_command_nonraw_paths(monkeypatch) -> None: monkeypatch.setattr(iocommands.locale, 'getpreferredencoding', lambda do_setlocale: 'utf-8')