feat: aggiungi indicatore 'Pensando...' durante elaborazione

- Spinner animato mostra che l'agent sta elaborando
- Previene confusione su operazioni lunghe
This commit is contained in:
opencode committed 2026-03-24 11:23:30 +01:00
1 parent c8e7489c26
commit 918b1f3a5b
1 file changed
+27 -2
+27 -2
View File
@@ -33,6 +33,8 @@ def cmd_chat(args):
"""Avvia l'agent in modalità chat interattiva"""
import signal
import sys
import threading
import time
from main import create_langcode_agent, process_command
from langchain_core.messages import HumanMessage
@@ -44,6 +46,20 @@ def cmd_chat(args):
# Register signal handler
signal.signal(signal.SIGINT, handle_sigint)
# Thread-safe flag for thinking indicator
thinking_active = threading.Event()
thinking_active.set()
def thinking_indicator():
"""Mostra indicatore di pensiero mentre aspetta"""
dots = [" ", ". ", ".. ", "..."]
idx = 0
while thinking_active.is_set():
print(f"\r🤖 Pensando{dots[idx % 4]} ", end="", flush=True)
idx += 1
time.sleep(0.5)
print("\r" + " " * 20 + "\r", end="") # Clear line
print("🚀 Inizializzo LangCode Agent...")
try:
@@ -133,8 +149,17 @@ Comandi disponibili:
# Mostra input utente
print(f"👤 {user_input}\n")
# Chiamata all'agent
response = agent_callback(user_input)
# Chiamata all'agent CON indicatore di pensiero
thinking_active.set()
thinker = threading.Thread(target=thinking_indicator, daemon=True)
thinker.start()
try:
response = agent_callback(user_input)
finally:
thinking_active.clear()
thinker.join(timeout=1)
print(f"🤖 {response}\n")
except KeyboardInterrupt: