fix(display): suppress spinner animation in non-TTY environments
In Docker/systemd/piped environments, the KawaiiSpinner animation generates ~500 log lines per tool call. Now checks isatty() and falls back to clean [tool]/[done] log lines in non-TTY contexts. Interactive CLI behavior unchanged. Based on work by 42-evey in PR #2203.
This commit is contained in:
parent
f853e50589
commit
6e2be3356d
1 changed files with 21 additions and 5 deletions
|
|
@ -254,6 +254,15 @@ class KawaiiSpinner:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _animate(self):
|
def _animate(self):
|
||||||
|
# When stdout is not a real terminal (e.g. Docker, systemd, pipe),
|
||||||
|
# skip the animation entirely — it creates massive log bloat.
|
||||||
|
# Just log the start once and let stop() log the completion.
|
||||||
|
if not hasattr(self._out, 'isatty') or not self._out.isatty():
|
||||||
|
self._write(f" [tool] {self.message}", flush=True)
|
||||||
|
while self.running:
|
||||||
|
time.sleep(0.5)
|
||||||
|
return
|
||||||
|
|
||||||
# Cache skin wings at start (avoid per-frame imports)
|
# Cache skin wings at start (avoid per-frame imports)
|
||||||
skin = _get_skin()
|
skin = _get_skin()
|
||||||
wings = skin.get_spinner_wings() if skin else []
|
wings = skin.get_spinner_wings() if skin else []
|
||||||
|
|
@ -319,12 +328,19 @@ class KawaiiSpinner:
|
||||||
self.running = False
|
self.running = False
|
||||||
if self.thread:
|
if self.thread:
|
||||||
self.thread.join(timeout=0.5)
|
self.thread.join(timeout=0.5)
|
||||||
# Clear the spinner line with spaces instead of \033[K to avoid
|
|
||||||
# garbled escape codes when prompt_toolkit's patch_stdout is active.
|
is_tty = hasattr(self._out, 'isatty') and self._out.isatty()
|
||||||
blanks = ' ' * max(self.last_line_len + 5, 40)
|
if is_tty:
|
||||||
self._write(f"\r{blanks}\r", 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:
|
if final_message:
|
||||||
self._write(f" {final_message}", flush=True)
|
elapsed = f" ({time.time() - self.start_time:.1f}s)" if self.start_time else ""
|
||||||
|
if is_tty:
|
||||||
|
self._write(f" {final_message}", flush=True)
|
||||||
|
else:
|
||||||
|
self._write(f" [done] {final_message}{elapsed}", flush=True)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.start()
|
self.start()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue