import sys
from typing import IO, Any

from colorama import Fore, Style, init

init()


def printx(*values: Any, sep: str = ' ', end: str = '\n', file: IO[str] = sys.stdout, flush: bool = False, colors: list[Any] | None):
    "color 数组参数 colorama.Fore / colorama.Back / colorama.Style 的常量"
    if colors:
        set_colors(*colors)
    print(*values, sep=sep, end=end, file=file, flush=flush)
    clear_colors()


def get_colors_str(value: Any, *colors: Any):
    if colors:
        value = ''.join(colors) + str(value) + Style.RESET_ALL
    return value


def set_colors(*colors: Any):
    content = ''.join(colors)
    if content:
        sys.stdout.write(content)
        sys.stderr.write(content)


def clear_colors():
    sys.stdout.write(Style.RESET_ALL)
    sys.stderr.write(Style.RESET_ALL)


def red(msg: str):
    return get_colors_str(msg, Fore.LIGHTRED_EX)


def yellow(msg: str):
    return get_colors_str(msg, Fore.YELLOW)


def green(msg: str):
    return get_colors_str(msg, Fore.LIGHTGREEN_EX)


def cyan(msg: str):
    "蓝色"
    return get_colors_str(msg, Fore.LIGHTCYAN_EX)


def magenta(msg: str):
    "紫色"
    return get_colors_str(msg, Fore.LIGHTMAGENTA_EX)


def white(msg: str):
    return get_colors_str(msg, Fore.LIGHTWHITE_EX)


def print_red(*values: Any):
    print(red(' '.join([str(x) for x in values])))


def print_yellow(*values: Any):
    print(yellow(' '.join([str(x) for x in values])))


def print_green(*values: Any):
    print(green(' '.join([str(x) for x in values])))


def print_cyan(*values: Any):
    "蓝色"
    print(cyan(' '.join([str(x) for x in values])))


def print_magenta(*values: Any):
    "紫色"
    print(magenta(' '.join([str(x) for x in values])))


def print_white(*values: Any):
    print(white(' '.join([str(x) for x in values])))
