refactor(cli): move the output-history row helpers out of the cli facade (#95375)

_output_history_lines / _output_history_rows are new in this PR; they belong with the
rest of the history rendering in hermes_cli/cli_render.py, not appended to cli.py.
cli.py imports them for _replay_output_history; the terminal mixin imports them from
cli_render directly.
This commit is contained in:
teknium1
2026-09-23 23:04:38 -07:00
committed by Teknium
parent a95242c15f
commit 0004e3a8df
3 changed files with 33 additions and 30 deletions

31
cli.py
View File

@@ -110,7 +110,9 @@ from hermes_cli.cli_render import ( # noqa: F401,E402
_line_rows,
_luminance_from_hex,
_maybe_remap_for_light_mode,
_output_history_lines,
_output_history_recording,
_output_history_rows,
_output_tail_fitting,
_painted_columns,
_PaintedLine,
@@ -654,35 +656,6 @@ def _suspend_output_history():
_OUTPUT_HISTORY_SUPPRESSED = old_value
def _output_history_lines() -> list[str]:
"""The recorded output as the lines a replay paints (callable entries render now)."""
rendered_lines = []
for entry in tuple(_OUTPUT_HISTORY):
lines = [entry]
if callable(entry):
try:
lines = entry()
except Exception:
continue
if isinstance(lines, str):
lines = lines.splitlines()
rendered_lines.extend(line if isinstance(line, str) else str(line) for line in lines)
return rendered_lines
def _output_history_rows(limit: int, columns: int, painted: bool):
"""Rows the whole recorded output fills (counted as ``_output_tail_fitting`` does), or
``None`` when that is ``limit`` rows or more."""
if not _OUTPUT_HISTORY_ENABLED:
return None
total = 0
for line in reversed(_output_history_lines()):
total += _line_rows(line, (getattr(line, "width", None) if painted else None) or columns)
if total >= limit:
return None
return total
def _replay_output_history(fit=None, output=None) -> None:
"""Repaint recent output above the prompt after a full screen clear.

View File

@@ -616,6 +616,35 @@ def _output_tail_fitting(lines: list[str], max_rows: int, columns: int, painted:
return kept
def _output_history_lines() -> list[str]:
"""The recorded output as the lines a replay paints (callable entries render now)."""
rendered_lines = []
for entry in tuple(_cli()._OUTPUT_HISTORY):
lines = [entry]
if callable(entry):
try:
lines = entry()
except Exception:
continue
if isinstance(lines, str):
lines = lines.splitlines()
rendered_lines.extend(line if isinstance(line, str) else str(line) for line in lines)
return rendered_lines
def _output_history_rows(limit: int, columns: int, painted: bool):
"""Rows the whole recorded output fills (counted as ``_output_tail_fitting`` does), or
``None`` when that is ``limit`` rows or more."""
if not _cli()._OUTPUT_HISTORY_ENABLED:
return None
total = 0
for line in reversed(_output_history_lines()):
total += _line_rows(line, (getattr(line, "width", None) if painted else None) or columns)
if total >= limit:
return None
return total
def _pt_print_ansi(text: str) -> None:
"""``_pt_print(ANSI(text))``, falling back to ``print`` when stdout is not a real console."""
from cli import _PT_ANSI, _pt_print

View File

@@ -14,6 +14,7 @@ import time
from hermes_cli.cli_render import (
_chrome_floor,
_hold_paints,
_output_history_rows,
_release_paints,
_set_chrome_floor,
_set_paint_gate,
@@ -221,7 +222,7 @@ class CLITerminalMixin:
drawn from there to the bottom (``_set_chrome_floor``), where the next count assumes it.
A clear that fails replays nothing: the history is already on screen or in scrollback.
"""
from cli import _output_history_rows, _terminal_reflows
from cli import _terminal_reflows
if getattr(self, "_terminal_io_broken", False):
return _NO_REPLAY
try: