diff --git a/langcode.py b/langcode.py index ec22fbf..dacb7ed 100755 --- a/langcode.py +++ b/langcode.py @@ -170,22 +170,32 @@ Comandi disponibili: # Strip ANSI codes per terminali semplici clean_response = strip_ansi(response) - # Paginazione con 'more' style per output lunghi + # Output con scrollback via less lines = clean_response.split('\n') - if len(lines) > 15: - for i in range(0, len(lines), 15): - chunk = '\n'.join(lines[i:i+15]) - print(f"šŸ¤– {chunk}") - if i + 15 < len(lines): - print("\n" + "─" * 40) - print("Premi ENTER per continuare, 'q' per uscire: ", end="") - try: - user_char = input() - if user_char.lower() == 'q': - break - except: - break - print() + if len(lines) > 10: + import tempfile + from datetime import datetime + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + output_file = f".langcode/output_{timestamp}.txt" + + # Save to file + os.makedirs(".langcode", exist_ok=True) + with open(output_file, "w") as f: + f.write(clean_response) + + print(f"šŸ¤– Output lungo salvato in: {output_file}") + print("šŸ’” Visualizza con: less {0} (usa frecce per scrollare, q per uscire)\n".format(output_file)) + + # Try to show with less + import subprocess + try: + subprocess.run(["less", "-R", output_file], check=False) + except FileNotFoundError: + # less not available, just cat first part + print("šŸ¤– " + "\nšŸ¤– ".join(lines[:20])) + if len(lines) > 20: + print(f"\n... (altre {len(lines)-20} righe nel file {output_file})") + print() else: print(f"šŸ¤– {clean_response}\n")