fix(cli): prevent spinner ANSI escape codes from being printed verbatim
Fixes #2591 The "nanobot is thinking..." spinner was printing ANSI escape codes literally in some terminals, causing garbled output like: ?[2K?[32m⠧?[0m ?[2mnanobot is thinking...?[0m Root causes: 1. Console created without force_terminal=True, so Rich couldn't reliably detect terminal capabilities 2. Spinner continued running during user input prompt, conflicting with prompt_toolkit Changes: - Set force_terminal=True in _make_console() for proper ANSI handling - Add stop_for_input() method to StreamRenderer - Call stop_for_input() before reading user input in interactive mode - Add tests for the new functionality
This commit is contained in:
@@ -1004,6 +1004,9 @@ def agent(
|
||||
while True:
|
||||
try:
|
||||
_flush_pending_tty_input()
|
||||
# Stop spinner before user input to avoid prompt_toolkit conflicts
|
||||
if renderer:
|
||||
renderer.stop_for_input()
|
||||
user_input = await _read_interactive_input_async()
|
||||
command = user_input.strip()
|
||||
if not command:
|
||||
|
||||
@@ -18,7 +18,7 @@ from nanobot import __logo__
|
||||
|
||||
|
||||
def _make_console() -> Console:
|
||||
return Console(file=sys.stdout)
|
||||
return Console(file=sys.stdout, force_terminal=True)
|
||||
|
||||
|
||||
class ThinkingSpinner:
|
||||
@@ -120,6 +120,10 @@ class StreamRenderer:
|
||||
else:
|
||||
_make_console().print()
|
||||
|
||||
def stop_for_input(self) -> None:
|
||||
"""Stop spinner before user input to avoid prompt_toolkit conflicts."""
|
||||
self._stop_spinner()
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Stop spinner/live without rendering a final streamed round."""
|
||||
if self._live:
|
||||
|
||||
Reference in New Issue
Block a user