from time import sleep




def tui_select(title, options):
    max_option_length = max(len(f"{i + 1}. {opt}") for i, opt in enumerate(options))
    box_width = max(len(title), max_option_length) + 4

    print("┌" + "─" * box_width + "┐")
    print("│ " + title.ljust(box_width - 2) + " │")
    print("├" + "─" * box_width + "┤")
    for i, opt in enumerate(options, start=1):
        line = f"{i}. {opt}"
        print("│ " + line.ljust(box_width - 2) + " │")
    print("└" + "─" * box_width + "┘")

    prompt = f"Enter [1..{len(options)}] or Q to cancel: "
    while True:
        choice = input(prompt).strip().lower()
        if choice == 'q':
            return None, None
        if choice.isdigit():
            index = int(choice) - 1
            if 0 <= index < len(options):
                return options[index], index
        print("Invalid input. Please try again.")


def slow_exit():
    print(T('exit'), end='', flush=True)
    sleep(1)
    print('.', end='', flush=True)
    sleep(1)
    print('.', end='', flush=True)
    sleep(1)
    print('.', end='', flush=True)
    sleep(1)
    exit(0)