fix: output lungo salvato in file + visualizzato con less per scrollback
- Output > 10 righe salvato in .langcode/output_TIMESTAMP.txt - Visualizzato con 'less -R' che supporta frecce e scroll - Fallback a cat parziale se less non disponibile
This commit is contained in:
1 parent
f1d1248d4b
commit
e75a75e16c
1 file changed
+25
-15
+25
-15
@@ -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")
|
||||
|
||||
|
||||
Reference in new issue
Block a user