fix(cli): improve spinner line clearing to prevent garbled output with prompt_toolkit
This commit is contained in:
@@ -182,9 +182,8 @@ class KawaiiSpinner:
|
||||
frame = self.spinner_frames[self.frame_idx % len(self.spinner_frames)]
|
||||
elapsed = time.time() - self.start_time
|
||||
line = f" {frame} {self.message} ({elapsed:.1f}s)"
|
||||
# Use \r + ANSI erase-to-EOL in a single write to avoid the
|
||||
# two-phase clear+redraw that flickers under patch_stdout.
|
||||
self._write(f"\r\033[K{line}", end='', flush=True)
|
||||
pad = max(self.last_line_len - len(line), 0)
|
||||
self._write(f"\r{line}{' ' * pad}", end='', flush=True)
|
||||
self.last_line_len = len(line)
|
||||
self.frame_idx += 1
|
||||
time.sleep(0.12)
|
||||
@@ -204,7 +203,10 @@ class KawaiiSpinner:
|
||||
self.running = False
|
||||
if self.thread:
|
||||
self.thread.join(timeout=0.5)
|
||||
self._write('\r\033[K', end='', flush=True)
|
||||
# Clear the spinner line with spaces instead of \033[K to avoid
|
||||
# garbled escape codes when prompt_toolkit's patch_stdout is active.
|
||||
blanks = ' ' * max(self.last_line_len + 5, 40)
|
||||
self._write(f"\r{blanks}\r", end='', flush=True)
|
||||
if final_message:
|
||||
self._write(f" {final_message}", flush=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user