mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(cli): improve spinner line clearing to prevent garbled output with prompt_toolkit
This commit is contained in:
parent
e09ef6b8bc
commit
c92bdd8785
2 changed files with 17 additions and 9 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue