from rich.console import Console
import os
import time
from colorama import Fore, Style, init as colorama_init

console = Console()

def run():
    while True:
        console.clear()
        console.rule("[bold yellow]Log's do NFDOS[/bold yellow]")
        console.print("1. Últimos eventos do sistema")
        console.print("2. (Placeholder)")
        console.print("0. Voltar")

        choice = console.input("\n[cyan]nfdos> [/cyan]")

        if choice == "1":
            """Mostra as últimas linhas do log."""
            log_path = os.path.expanduser("~/.nfdos.log")
            console.print(f"\n[bold yellow]Últimos eventos do sistema:[/]\n")
            if os.path.exists(log_path):
                with open(log_path, "r") as f:
                    for line in f.readlines()[-10:]:
                        console.print(line.strip())
            else:
                console.print(f"{Fore.RED}[✗]{Style.RESET_ALL} Nenhum log encontrado.")
        elif choice == "2":
            time.sleep(0.5)
        elif choice == "0":
            break
        else:
            console.print("[red]Opção inválida![/red]")