From 4ec386cc724f8822aa188c72c89c034726bad7aa Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sat, 28 Feb 2026 23:19:23 -0800 Subject: [PATCH] fix(display): use spaces instead of ANSI \033[K in print_above() for prompt_toolkit compat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit print_above() used \033[K (erase-to-end-of-line) to clear the spinner line before printing text above it. This causes garbled escape codes when prompt_toolkit's patch_stdout is active in CLI mode. Switched to the same spaces-based clearing approach used by stop() — overwrite with blanks, then carriage return back to start of line. Updated test assertion to match the new clearing method. --- agent/display.py | 7 +++++-- tests/agent/test_subagent_progress.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/agent/display.py b/agent/display.py index 19acc67d..e7f074c4 100644 --- a/agent/display.py +++ b/agent/display.py @@ -211,8 +211,11 @@ class KawaiiSpinner: if not self.running: self._write(f" {text}", flush=True) return - # Clear spinner line, print text above, spinner redraws on next tick - self._write(f"\r\033[K {text}", flush=True) + # Clear spinner line with spaces (not \033[K) to avoid garbled escape + # codes when prompt_toolkit's patch_stdout is active — same approach + # as stop(). Then print text; spinner redraws on next tick. + blanks = ' ' * max(self.last_line_len + 5, 40) + self._write(f"\r{blanks}\r {text}", flush=True) def stop(self, final_message: str = None): self.running = False diff --git a/tests/agent/test_subagent_progress.py b/tests/agent/test_subagent_progress.py index 0ff4fcb8..0aa39f4c 100644 --- a/tests/agent/test_subagent_progress.py +++ b/tests/agent/test_subagent_progress.py @@ -46,7 +46,7 @@ class TestPrintAbove: spinner.print_above("tool line") output = buf.getvalue() assert "tool line" in output - assert "\r\033[K" in output # Should start with line clear + assert "\r" in output # Should start with carriage return to clear spinner line def test_print_above_uses_captured_stdout(self): """print_above should use self._out, not sys.stdout.