mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 20:54:59 +00:00
refactor: Centralize spinner logic in BaseCoder
This commit is contained in:
parent
0864a7ca76
commit
befff1f22e
2 changed files with 8 additions and 24 deletions
|
@ -1418,11 +1418,12 @@ class Coder:
|
||||||
utils.show_messages(messages, functions=self.functions)
|
utils.show_messages(messages, functions=self.functions)
|
||||||
|
|
||||||
self.multi_response_content = ""
|
self.multi_response_content = ""
|
||||||
if self.show_pretty() and self.stream:
|
if self.show_pretty():
|
||||||
self.mdstream = self.io.get_assistant_mdstream()
|
|
||||||
elif self.show_pretty(): # pretty output but NOT streaming
|
|
||||||
self.waiting_spinner = WaitingSpinner("Waiting for LLM")
|
self.waiting_spinner = WaitingSpinner("Waiting for LLM")
|
||||||
self.waiting_spinner.start()
|
self.waiting_spinner.start()
|
||||||
|
if self.stream:
|
||||||
|
self.mdstream = self.io.get_assistant_mdstream()
|
||||||
|
else:
|
||||||
self.mdstream = None
|
self.mdstream = None
|
||||||
else:
|
else:
|
||||||
self.mdstream = None
|
self.mdstream = None
|
||||||
|
@ -1932,6 +1933,8 @@ class Coder:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if received_content:
|
||||||
|
self._stop_waiting_spinner()
|
||||||
self.partial_response_content += text
|
self.partial_response_content += text
|
||||||
|
|
||||||
if self.show_pretty():
|
if self.show_pretty():
|
||||||
|
|
|
@ -12,7 +12,6 @@ from rich.syntax import Syntax
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
from aider.dump import dump # noqa: F401
|
from aider.dump import dump # noqa: F401
|
||||||
from aider.waiting import WaitingSpinner
|
|
||||||
|
|
||||||
_text_prefix = """
|
_text_prefix = """
|
||||||
# Header
|
# Header
|
||||||
|
@ -116,19 +115,10 @@ class MarkdownStream:
|
||||||
else:
|
else:
|
||||||
self.mdargs = dict()
|
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.live = None
|
||||||
self.waiting_spinner = WaitingSpinner("Waiting for LLM")
|
|
||||||
self.waiting_spinner.start()
|
|
||||||
self._spinner_running = True
|
|
||||||
self._live_started = False
|
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):
|
def _render_markdown_to_lines(self, text):
|
||||||
"""Render markdown text to a list of lines.
|
"""Render markdown text to a list of lines.
|
||||||
|
@ -157,12 +147,6 @@ class MarkdownStream:
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # Ignore any errors during cleanup
|
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):
|
def update(self, text, final=False):
|
||||||
"""Update the displayed markdown content.
|
"""Update the displayed markdown content.
|
||||||
|
@ -183,9 +167,6 @@ class MarkdownStream:
|
||||||
"""
|
"""
|
||||||
# On the first call, stop the spinner and start the Live renderer
|
# On the first call, stop the spinner and start the Live renderer
|
||||||
if not getattr(self, "_live_started", False):
|
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 = Live(Text(""), refresh_per_second=1.0 / self.min_delay)
|
||||||
self.live.start()
|
self.live.start()
|
||||||
self._live_started = True
|
self._live_started = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue