From befff1f22e4ead3ba68685f2507dbf9f64b9f951 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 8 May 2025 16:06:44 -0700 Subject: [PATCH] refactor: Centralize spinner logic in BaseCoder --- aider/coders/base_coder.py | 11 +++++++---- aider/mdstream.py | 21 +-------------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 5a04da7ad..f68e3bead 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1418,12 +1418,13 @@ class Coder: utils.show_messages(messages, functions=self.functions) self.multi_response_content = "" - if self.show_pretty() and self.stream: - self.mdstream = self.io.get_assistant_mdstream() - elif self.show_pretty(): # pretty output but NOT streaming + if self.show_pretty(): self.waiting_spinner = WaitingSpinner("Waiting for LLM") self.waiting_spinner.start() - self.mdstream = None + if self.stream: + self.mdstream = self.io.get_assistant_mdstream() + else: + self.mdstream = None else: self.mdstream = None @@ -1932,6 +1933,8 @@ class Coder: except AttributeError: pass + if received_content: + self._stop_waiting_spinner() self.partial_response_content += text if self.show_pretty(): diff --git a/aider/mdstream.py b/aider/mdstream.py index 186ef7624..4e76d7735 100755 --- a/aider/mdstream.py +++ b/aider/mdstream.py @@ -12,7 +12,6 @@ from rich.syntax import Syntax from rich.text import Text from aider.dump import dump # noqa: F401 -from aider.waiting import WaitingSpinner _text_prefix = """ # Header @@ -116,19 +115,10 @@ class MarkdownStream: else: self.mdargs = dict() - # Defer Live creation until the first update so the spinner can be shown. + # Defer Live creation until the first update. self.live = None - self.waiting_spinner = WaitingSpinner("Waiting for LLM") - self.waiting_spinner.start() - self._spinner_running = True self._live_started = False - def _spin(self): - """Background thread that keeps the spinner moving until stopped.""" - while not self._spinner_stop_event.is_set(): - time.sleep(0.15) - self.spinner.step() - self.spinner.end() def _render_markdown_to_lines(self, text): """Render markdown text to a list of lines. @@ -157,12 +147,6 @@ class MarkdownStream: except Exception: pass # Ignore any errors during cleanup - # Ensure the spinner is properly shut down - if getattr(self, "_spinner_running", False): - try: - self.waiting_spinner.stop() - except Exception: - pass def update(self, text, final=False): """Update the displayed markdown content. @@ -183,9 +167,6 @@ class MarkdownStream: """ # On the first call, stop the spinner and start the Live renderer if not getattr(self, "_live_started", False): - if getattr(self, "_spinner_running", False): - self.waiting_spinner.stop() - self._spinner_running = False self.live = Live(Text(""), refresh_per_second=1.0 / self.min_delay) self.live.start() self._live_started = True