<filename>interface.py
color_blue = "\033[94m"
color_green = "\033[92m"
color_red = "\033[91m"
color_end = "\033[0m"

underline = "\033[4m"

class prompt:
    # Prompts the user for input
    # n will be replaced with the number of the prompt
    # s will be replaced with spaces to compensate for the length
    def __init__(self, options, tick="[n]s - ", prompt="> ", overrideValues={}) -> None:
        self.options = options
        self.tick = tick
        self.prompt = prompt
        self.overrideValues = overrideValues
    
    def add_option(self, option) -> None:
        self.options.append(option)

    def remove_option(self, option) -> None:
        self.options.remove(option)

    def get_input(self) -> int:
        # Returns the index of the option selected
        for i in range(len(self.options)):
            print(self.tick.replace("n", format_text(str(i), "blue")).replace("s", " " * (len(str(len(self.options))) - len(str(i)) - 1)) + self.options[i])
        while True:
            i = input(self.prompt)
            try:
                return int(i)
            except ValueError:
                if i in self.overrideValues:
                    return i
                print("Please enter a number:")


def format_text(text, color="None", use_underline=False) -> str:
    prefix = ""
    if color == "blue":
        prefix = color_blue
    elif color == "green":
        prefix = color_green
    elif color == "red":
        prefix = color_red
    elif color == "underline":
        prefix = underline
    if use_underline:
        prefix += underline
    return prefix + text + color_end
