mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-19 16:12:30 +00:00
feat(cli): make stream renderer use bot_name and bot_icon (#3650)
Threads bot_name/bot_icon through ThinkingSpinner and StreamRenderer with safe defaults that preserve current behavior. - ThinkingSpinner uses bot_name in its status text - StreamRenderer header is "<icon> <name>" when icon is set, or just "<name>" when icon is empty - Removes the now-unused __logo__ import (the cat emoji is the default value of bot_icon, not a hardcoded constant)
This commit is contained in:
parent
fcf9d110dd
commit
86693f5422
@ -14,8 +14,6 @@ from rich.live import Live
|
||||
from rich.markdown import Markdown
|
||||
from rich.text import Text
|
||||
|
||||
from nanobot import __logo__
|
||||
|
||||
|
||||
def _make_console() -> Console:
|
||||
"""Create a Console that emits plain text when stdout is not a TTY.
|
||||
@ -32,11 +30,11 @@ def _make_console() -> Console:
|
||||
|
||||
|
||||
class ThinkingSpinner:
|
||||
"""Spinner that shows 'nanobot is thinking...' with pause support."""
|
||||
"""Spinner that shows '<bot_name> is thinking...' with pause support."""
|
||||
|
||||
def __init__(self, console: Console | None = None):
|
||||
def __init__(self, console: Console | None = None, bot_name: str = "nanobot"):
|
||||
c = console or _make_console()
|
||||
self._spinner = c.status("[dim]nanobot is thinking...[/dim]", spinner="dots")
|
||||
self._spinner = c.status(f"[dim]{bot_name} is thinking...[/dim]", spinner="dots")
|
||||
self._active = False
|
||||
|
||||
def __enter__(self):
|
||||
@ -76,9 +74,17 @@ class StreamRenderer:
|
||||
on_end -> Live stops (content stays on screen)
|
||||
"""
|
||||
|
||||
def __init__(self, render_markdown: bool = True, show_spinner: bool = True):
|
||||
def __init__(
|
||||
self,
|
||||
render_markdown: bool = True,
|
||||
show_spinner: bool = True,
|
||||
bot_name: str = "nanobot",
|
||||
bot_icon: str = "🐈",
|
||||
):
|
||||
self._md = render_markdown
|
||||
self._show_spinner = show_spinner
|
||||
self._bot_name = bot_name
|
||||
self._bot_icon = bot_icon
|
||||
self._buf = ""
|
||||
self._live: Live | None = None
|
||||
self._t = 0.0
|
||||
@ -91,7 +97,7 @@ class StreamRenderer:
|
||||
|
||||
def _start_spinner(self) -> None:
|
||||
if self._show_spinner:
|
||||
self._spinner = ThinkingSpinner()
|
||||
self._spinner = ThinkingSpinner(bot_name=self._bot_name)
|
||||
self._spinner.__enter__()
|
||||
|
||||
def _stop_spinner(self) -> None:
|
||||
@ -108,7 +114,8 @@ class StreamRenderer:
|
||||
self._stop_spinner()
|
||||
c = _make_console()
|
||||
c.print()
|
||||
c.print(f"[cyan]{__logo__} nanobot[/cyan]")
|
||||
header = f"{self._bot_icon} {self._bot_name}" if self._bot_icon else self._bot_name
|
||||
c.print(f"[cyan]{header}[/cyan]")
|
||||
self._live = Live(self._render(), console=c, auto_refresh=False)
|
||||
self._live.start()
|
||||
now = time.monotonic()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user