prompting: end an open tool line before writing a prompt

This commit is contained in:
2026-10-06 19:06:22 +08:00
parent a81b138bf8
commit 1068ea0025
5 changed files with 81 additions and 3 deletions
+23
View File
@@ -7,6 +7,7 @@ from plyngent.cli.display import (
_clear_streamed_lines,
_line_count_for_clear,
_pretty_line_for,
close_open_pretty_line,
get_markdown_enabled,
markdown_render_available,
print_markdown,
@@ -1002,6 +1003,28 @@ async def test_pretty_parallel_batch_keeps_the_line_above_the_prefix(
assert "\x1b[" not in out
async def test_pretty_line_closed_by_out_of_band_output(
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
"""A prompt/confirm printed while the call runs ends the open prefix line.
The prompt backend runs :func:`close_open_pretty_line` before writing, so its
box starts on a fresh line and the result then prints whole.
"""
monkeypatch.setattr("plyngent.cli.display.interactive_terminal", lambda: True)
async def _events():
yield _pretty_call("read_file", '{"path": "a.txt"}')
close_open_pretty_line() # what a confirm box does mid-call
yield _result("L1-4\none\n")
await render_events(_events())
out = capsys.readouterr().out
assert out == ("\n* Read 'a.txt' \n\n* Read 'a.txt' L1-4 (done)\n\n")
assert "\x1b[" not in out
def test_clear_streamed_lines_clears_exactly_the_given_rows(capsys: pytest.CaptureFixture[str]) -> None:
"""Two rows means two clears; the cursor lands on the topmost cleared row."""
_clear_streamed_lines(2)