import unittest
from ansi_terminal import ansi_print, ansi_string, Color, fg, bg, style, reset, Display, erase, Cursor, move


class Test(unittest.TestCase):
    def test_color_foreground_names(self):
        color_list = (
            ("black", Color(fg.black)),
            ("red", Color(fg.red)),
            ("green", Color(fg.green)),
            ("yellow", Color(fg.yellow)),
            ("blue", Color(fg.blue)),
            ("magenta", Color(fg.magenta)),
            ("cyan", Color(fg.cyan)),
            ("white", Color(fg.white)),
            ("", Color()),
            ("bright_black", Color(fg.bright_black)),
            ("bright_red", Color(fg.bright_red)),
            ("bright_green", Color(fg.bright_green)),
            ("bright_yellow", Color(fg.bright_yellow)),
            ("bright_blue", Color(fg.bright_blue)),
            ("bright_magenta", Color(fg.bright_magenta)),
            ("bright_cyan", Color(fg.bright_cyan)),
            ("bright_white", Color(fg.bright_white)),
            ("", Color())
        )
        for color in color_list:
            if color[0] == "":
                ansi_print()
            else:
                ansi_print(f"{color[0]:18}", color=color[1], end="")

    def test_color_background_names(self):
        color_list = (
            ("black", Color(bg.black)),
            ("red", Color(bg.red)),
            ("green", Color(bg.green)),
            ("yellow", Color(bg.yellow)),
            ("blue", Color(bg.blue)),
            ("magenta", Color(bg.magenta)),
            ("cyan", Color(bg.cyan)),
            ("white", Color(bg.white)),
            ("", Color()),
            ("bright_black", Color(bg.bright_black)),
            ("bright_red", Color(bg.bright_red)),
            ("bright_green", Color(bg.bright_green)),
            ("bright_yellow", Color(bg.bright_yellow)),
            ("bright_blue", Color(bg.bright_blue)),
            ("bright_magenta", Color(bg.bright_magenta)),
            ("bright_cyan", Color(bg.bright_cyan)),
            ("bright_white", Color(bg.bright_white)),
            ("", Color())
        )
        for color in color_list:
            if color[0] == "":
                ansi_print()
            else:
                ansi_print(f"{color[0]:18}", color=color[1], end="")

    def test_color_id(self):
        for color_id in range(0, 16):
            ansi_print(f"{color_id:18}", color=Color(bg.id(color_id)), end=f"")
            if color_id in [7, 15, 51, 87, 123, 159, 195, 231, 255]:
                ansi_print()

        for color_id in range(16, 232):
            ansi_print(f"{color_id:4}", color=Color(bg.id(color_id)), end=f"")
            if color_id in [7, 15, 51, 87, 123, 159, 195, 231, 255]:
                ansi_print()

        for color_id in range(232, 256):
            ansi_print(f"{color_id:6}", color=Color(bg.id(color_id)), end=f"")
            if color_id in [7, 15, 51, 87, 123, 159, 195, 231, 255]:
                ansi_print()

    def test_color_rgb(self):
        for color_r in range(0, 256, 32):
            for color_g in range(0, 256, 48):
                for color_b in range(0, 256, 11):
                    ansi_print(f" ", color=Color(bg.rgb(color_r, color_g, color_b)), end=f"")
            ansi_print()

    def test_style(self):
        color_list = {
            "bold": Color(style.bold),
            "faint": Color(style.faint),
            "italic": Color(style.italic),
            "underline": Color(style.underline),
            "blink_slow": Color(style.blink_slow),
            "blink_fast": Color(style.blink_fast),
            "invert_color": Color(style.invert_color),
            "hide": Color(style.hide),
            "strike": Color(style.strike),
            "reset_font": Color(style.reset_font),
            "font_1": Color(style.font_1),
            "font_2": Color(style.font_2),
            "font_3": Color(style.font_3),
            "font_4": Color(style.font_4),
            "font_5": Color(style.font_5),
            "font_6": Color(style.font_6),
            "font_7": Color(style.font_7),
            "font_8": Color(style.font_8),
            "font_9": Color(style.font_9),
            "gothic": Color(style.gothic),
            "underline_double": Color(style.underline_double)
        }
        for color in color_list.items():
            ansi_print(color[0], color=color[1])


if __name__ == '__main__':
    unittest.main()
