import platform
import os

def init():
    if platform.system() == "Windows":
        os.system('')

def rgb_to_ansi(r, g, b):
    return f"\033[38;2;{r};{g};{b}m"

def hsl_to_rgb(h, s, l):
    import colorsys
    r, g, b = colorsys.hls_to_rgb(h/360, l/100, s/100)
    return int(r*255), int(g*255), int(b*255)

predefined_colors = {
    "black": "#000000",
    "red": "#FF0000",
    "green": "#00FF00",
    "blue": "#0000FF",
    "yellow": "#FFFF00",
    "cyan": "#00FFFF",
    "magenta": "#FF00FF",
    "white": "#FFFFFF",
    "gray": "#808080",
    "orange": "#FFA500",
    "pink": "#FFC0CB",
    "purple": "#800080",
    "brown": "#A52A2A",
    "lime": "#BFFF00",
    "teal": "#008080",
    "indigo": "#4B0082",
    "gold": "#FFD700",
    "silver": "#C0C0C0",
    "maroon": "#800000",
}

class Color:
    reset = "\033[0m"

    black   = "\033[30m"
    red     = "\033[31m"
    green   = "\033[32m"
    yellow  = "\033[33m"
    blue    = "\033[34m"
    magenta = "\033[35m"
    cyan    = "\033[36m"
    white   = "\033[37m"

    def hex(self, hex_code):
        hex_code = hex_code.lstrip("#")
        r, g, b = tuple(int(hex_code[i:i+2], 16) for i in (0, 2, 4))
        return rgb_to_ansi(r, g, b)

    def rgb(self, r, g, b):
        return rgb_to_ansi(r, g, b)

    def hsl(self, h, s, l):
        r, g, b = hsl_to_rgb(h, s, l)
        return rgb_to_ansi(r, g, b)

color = Color()
