# SPDX-FileCopyrightText: 2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later

import sys


class COLORS_ANSI:
    RED = '\033[00;31m'
    GREEN = '\033[00;32m'
    YELLOW = '\033[00;33m'
    ENDC = '\033[0m'


class COLORS_NONE:
    RED = ''
    GREEN = ''
    YELLOW = ''
    ENDC = ''


COLORS = COLORS_NONE


def use_message_colors():
    global COLORS, COLORS_ANSI
    COLORS = COLORS_ANSI


def print_message(message, type=None, status=''):
    if type == 'SUCCESS':
        print(COLORS.GREEN, end="")
    elif type == 'FAILURE':
        print(COLORS.RED, end="")
    elif type == 'WARNING':
        print(COLORS.YELLOW, end="")
    if status == "RAW":
        print("{}" . format(message))
        print(COLORS.ENDC, end="")
        sys.stdout.flush()
        return
    status_text = ...
    if status == 'RUN':
        status_text = " RUN      "
    elif status == 'OK':
        status_text = "       OK "
    elif status == 'PASSED':
        status_text = " PASSED   "
    elif status == 'FAILED':
        status_text = " FAILED   "
    else:
        status_text = status
    if status_text:
        print("[{}]" . format(status_text), end="")
    print(COLORS.ENDC, end="")
    print(" {}" . format(message))
    sys.stdout.flush()
