mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-25 05:52:34 +00:00
fix(cli): batch resize history replay
This commit is contained in:
parent
fe83c4001b
commit
06c6c1f0f2
2 changed files with 26 additions and 3 deletions
12
cli.py
12
cli.py
|
|
@ -1473,6 +1473,7 @@ def _replay_output_history() -> None:
|
||||||
return
|
return
|
||||||
_OUTPUT_HISTORY_REPLAYING = True
|
_OUTPUT_HISTORY_REPLAYING = True
|
||||||
try:
|
try:
|
||||||
|
rendered_lines = []
|
||||||
for entry in tuple(_OUTPUT_HISTORY):
|
for entry in tuple(_OUTPUT_HISTORY):
|
||||||
if callable(entry):
|
if callable(entry):
|
||||||
try:
|
try:
|
||||||
|
|
@ -1483,8 +1484,15 @@ def _replay_output_history() -> None:
|
||||||
lines = lines.splitlines()
|
lines = lines.splitlines()
|
||||||
else:
|
else:
|
||||||
lines = [entry]
|
lines = [entry]
|
||||||
for line in lines:
|
rendered_lines.extend(str(line) for line in lines)
|
||||||
_pt_print(_PT_ANSI(str(line)))
|
if rendered_lines:
|
||||||
|
# Replay after resize can contain hundreds of history lines. A
|
||||||
|
# per-line prompt_toolkit print forces one synchronous terminal I/O
|
||||||
|
# and redraw cycle per line, which users perceive as a waterfall of
|
||||||
|
# old output. Keep the existing history contents unchanged, but
|
||||||
|
# emit the replay as one ANSI payload so resize recovery does a
|
||||||
|
# single prompt_toolkit print/redraw.
|
||||||
|
_pt_print(_PT_ANSI("\n".join(rendered_lines)))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
|
|
@ -258,10 +258,25 @@ def test_replay_output_history_rerenders_callable_entries(monkeypatch):
|
||||||
cli._replay_output_history()
|
cli._replay_output_history()
|
||||||
|
|
||||||
assert widths_seen == ["called"]
|
assert widths_seen == ["called"]
|
||||||
assert printed == ["top border", "body"]
|
assert printed == ["top border\nbody"]
|
||||||
assert list(cli._OUTPUT_HISTORY) == [_render_current_width]
|
assert list(cli._OUTPUT_HISTORY) == [_render_current_width]
|
||||||
|
|
||||||
|
|
||||||
|
def test_replay_output_history_batches_rendered_lines_into_one_print(monkeypatch):
|
||||||
|
cli._configure_output_history(True, 10)
|
||||||
|
cli._record_output_history("first line")
|
||||||
|
cli._record_output_history("second line")
|
||||||
|
cli._record_output_history_entry(lambda: ["third line", "fourth line"])
|
||||||
|
printed = []
|
||||||
|
|
||||||
|
monkeypatch.setattr(cli, "_pt_print", lambda value: printed.append(value))
|
||||||
|
monkeypatch.setattr(cli, "_PT_ANSI", lambda text: text)
|
||||||
|
|
||||||
|
cli._replay_output_history()
|
||||||
|
|
||||||
|
assert printed == ["first line\nsecond line\nthird line\nfourth line"]
|
||||||
|
|
||||||
|
|
||||||
def test_suspend_output_history_blocks_recording():
|
def test_suspend_output_history_blocks_recording():
|
||||||
cli._configure_output_history(True, 10)
|
cli._configure_output_history(True, 10)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue