mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
cli: pretty printed summary for wait tool
This commit is contained in:
@@ -53,6 +53,7 @@ _PRETTY_TOOLS = frozenset(
|
||||
"delete_path",
|
||||
"vcs_status",
|
||||
"vcs_log",
|
||||
"wait",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -380,6 +381,15 @@ def _vcs_log_pretty(_args_json: str, result: str) -> str:
|
||||
return _pretty_line("* VCS Log ", (f"({len(commits)} {unit})", None))
|
||||
|
||||
|
||||
def _wait_pretty(_args_json: str, result: str) -> str:
|
||||
"""One-line summary for a ``wait`` call: ``* Wait (5s)`` / ``* Wait (disturbed)``."""
|
||||
if result.startswith("error:"):
|
||||
return _pretty_line("* Wait ", (f"({result})", "red"))
|
||||
if result.startswith("waited "):
|
||||
return _pretty_line("* Wait ", (f"({result.removeprefix('waited ')})", "green"))
|
||||
return _pretty_line("* Wait ", ("(disturbed)", "yellow"))
|
||||
|
||||
|
||||
_PRETTY_BUILDERS: dict[str, Callable[[str, str], str]] = {
|
||||
"read_file": _read_file_pretty,
|
||||
"tree": _tree_pretty,
|
||||
@@ -399,6 +409,7 @@ _PRETTY_BUILDERS: dict[str, Callable[[str, str], str]] = {
|
||||
"delete_path": lambda args, result: _mutator_pretty("delete_path", args, result),
|
||||
"vcs_status": _vcs_status_pretty,
|
||||
"vcs_log": _vcs_log_pretty,
|
||||
"wait": _wait_pretty,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -530,3 +530,23 @@ async def test_pretty_vcs_log_no_commits(capsys: pytest.CaptureFixture[str]) ->
|
||||
await render_events(_aiter([_pretty_call("vcs_log", "{}"), _result("(no commits)")]))
|
||||
out = capsys.readouterr().out
|
||||
assert "* VCS Log (no commits)" in out
|
||||
|
||||
|
||||
async def test_pretty_wait_waited(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
await render_events(_aiter([_pretty_call("wait", '{"duration": 5}'), _result("waited 5s")]))
|
||||
out = capsys.readouterr().out
|
||||
assert "* Wait (5s)" in out
|
||||
assert "[tool]" not in out
|
||||
|
||||
|
||||
async def test_pretty_wait_disturbed(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
await render_events(_aiter([_pretty_call("wait", '{"duration": 30}'), _result("disturbed by user: ship it")]))
|
||||
out = capsys.readouterr().out
|
||||
assert "* Wait (disturbed)" in out
|
||||
|
||||
|
||||
async def test_pretty_wait_error(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
content = "error: duration must not be negative"
|
||||
await render_events(_aiter([_pretty_call("wait", '{"duration": -1}'), _result(content)]))
|
||||
out = capsys.readouterr().out
|
||||
assert "* Wait (error: duration must not be negative)" in out
|
||||
|
||||
Reference in New Issue
Block a user