From 9532eebb7437bcb72cf50cc1db3e4b8acf7a8b99 Mon Sep 17 00:00:00 2001 From: Marcel <49859266+goodguy1963@users.noreply.github.com> Date: Sat, 16 May 2026 10:18:19 +0200 Subject: [PATCH] Add rolling \r terminal display for compact streaming mode --- AILab_StreamDisplay.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/AILab_StreamDisplay.py b/AILab_StreamDisplay.py index cc72bd5..14fdc99 100644 --- a/AILab_StreamDisplay.py +++ b/AILab_StreamDisplay.py @@ -183,19 +183,22 @@ class TerminalStreamDisplay: sys.stdout.write(msg) sys.stdout.flush() - def _write_stdout_line(self, text: str): - if not text: + def _write_rolling_line(self, label: str, tail: str, final: bool = False): + """Emit a carriage-return line showing the last ~200 chars, clearing to EOL. + 'final' adds a trailing newline so the last frame stays visible.""" + if not tail: return - msg = f"{text}\n" + msg = f"\r[{label}] {tail}\033[K" sys.stdout.write(msg) + if final: + sys.stdout.write("\n") sys.stdout.flush() def push_compact(self, text: str): - """Append *text* and print readable throttled snapshots. + """Append *text* and emit a carriage-return rolling tail every throttle interval. - Carriage-return rewrites look fine in a raw terminal, but ComfyUI's log - capture turns them into duplicated high-speed garbage. Emit a compact - line snapshot only when enough text or time has accumulated. + Uses \\r to redraw a single line so the terminal stays clean without + flooding the ComfyUI log buffer. """ if not text: return @@ -215,13 +218,13 @@ class TerminalStreamDisplay: self._stage_updates += 1 self._last_compact_tail = tail self._last_compact_emit_at = now - self._write_stdout_line(f"[{self.label}] {tail}") + self._write_rolling_line(self.label, tail) def end_compact(self): - """Finish compact mode with one final readable snapshot.""" + """Finish compact mode with one final newline-terminated snapshot.""" tail = self._compact_tail() if tail and tail != self._last_compact_tail: self._stage_updates += 1 - self._write_stdout_line(f"[{self.label}] {tail}") self._last_compact_tail = "" - self._last_compact_emit_at = 0.0 \ No newline at end of file + self._last_compact_emit_at = 0.0 + self._write_rolling_line(self.label, tail or "", final=True)