From 3197dedd4cbde81cb66e6221ed6b111e368f631e Mon Sep 17 00:00:00 2001 From: opencode Date: Tue, 24 Mar 2026 14:13:50 +0100 Subject: [PATCH] fix: rimuovi codici ANSI e aggiungi info scroll per CLI semplice - strip_ansi() rimuove escape sequences per terminali base - Info scroll per output > 1000 caratteri --- langcode.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/langcode.py b/langcode.py index 6cf577d..545058b 100755 --- a/langcode.py +++ b/langcode.py @@ -29,6 +29,13 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) VERSION = "1.0.0" +def strip_ansi(text: str) -> str: + """Rimuove codici ANSI escape sequences per terminali semplici""" + import re + ansi_pattern = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + return ansi_pattern.sub('', text) + + def cmd_chat(args): """Avvia l'agent in modalità chat interattiva""" import signal @@ -160,7 +167,13 @@ Comandi disponibili: thinking_active.clear() thinker.join(timeout=1) - print(f"🤖 {response}\n") + # Strip ANSI codes per terminali semplici + clean_response = strip_ansi(response) + print(f"🤖 {clean_response}\n") + + # Info scroll per output lunghi + if len(clean_response) > 1000: + print("💡 Suggerimento: scorri con Shift+PgUp / Shift+PgDn o mouse\n") except KeyboardInterrupt: print("\n👋 Arrivederci!")