fix: preserve ansi output history on resize replay

This commit is contained in:
LeonSGP43 2026-05-12 17:37:27 +08:00 committed by Teknium
parent 6244535682
commit ac64d0c2ca
2 changed files with 17 additions and 8 deletions

9
cli.py
View file

@ -1415,9 +1415,6 @@ _OUTPUT_HISTORY_REPLAYING = False
_OUTPUT_HISTORY_SUPPRESSED = False
_OUTPUT_HISTORY_MAX_LINES = 200
_OUTPUT_HISTORY = deque(maxlen=_OUTPUT_HISTORY_MAX_LINES)
_ANSI_CONTROL_RE = re.compile(
r"\x1b(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1b\\))"
)
def _coerce_output_history_limit(value) -> int:
@ -1459,10 +1456,10 @@ def _record_output_history_entry(entry) -> None:
def _record_output_history(text: str) -> None:
if not _OUTPUT_HISTORY_ENABLED or _OUTPUT_HISTORY_REPLAYING or _OUTPUT_HISTORY_SUPPRESSED:
return
clean = _ANSI_CONTROL_RE.sub("", str(text)).replace("\r", "").rstrip("\n")
if not clean:
normalized = str(text).replace("\r", "").rstrip("\n")
if not normalized:
return
for line in clean.splitlines():
for line in normalized.splitlines():
_record_output_history_entry(line)