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.