// vim:fileencoding=utf-8:foldmethod=marker

#include "../../../../common/aliases/aliases.h"
#include "../../../../common/platform/platform.h"
#include "../../../../base/strings/str8/str8.h"

#ifdef WAPP_PLATFORM_POSIX

#include "../terminal_colours.h"
#include <stdio.h>

wapp_intern Str8RO colours[COUNT_TERM_COLOUR] = {
    [WAPP_TERM_COLOUR_FG_BLACK]      = wapp_str8_lit_ro_initialiser_list("\033[30m"),
    [WAPP_TERM_COLOUR_FG_RED]        = wapp_str8_lit_ro_initialiser_list("\033[31m"),
    [WAPP_TERM_COLOUR_FG_GREEN]      = wapp_str8_lit_ro_initialiser_list("\033[32m"),
    [WAPP_TERM_COLOUR_FG_BLUE]       = wapp_str8_lit_ro_initialiser_list("\033[34m"),
    [WAPP_TERM_COLOUR_FG_CYAN]       = wapp_str8_lit_ro_initialiser_list("\033[36m"),
    [WAPP_TERM_COLOUR_FG_MAGENTA]    = wapp_str8_lit_ro_initialiser_list("\033[35m"),
    [WAPP_TERM_COLOUR_FG_YELLOW]     = wapp_str8_lit_ro_initialiser_list("\033[33m"),
    [WAPP_TERM_COLOUR_FG_WHITE]      = wapp_str8_lit_ro_initialiser_list("\033[37m"),
    [WAPP_TERM_COLOUR_FG_BR_BLACK]   = wapp_str8_lit_ro_initialiser_list("\033[90m"),
    [WAPP_TERM_COLOUR_FG_BR_RED]     = wapp_str8_lit_ro_initialiser_list("\033[91m"),
    [WAPP_TERM_COLOUR_FG_BR_GREEN]   = wapp_str8_lit_ro_initialiser_list("\033[92m"),
    [WAPP_TERM_COLOUR_FG_BR_BLUE]    = wapp_str8_lit_ro_initialiser_list("\033[94m"),
    [WAPP_TERM_COLOUR_FG_BR_CYAN]    = wapp_str8_lit_ro_initialiser_list("\033[96m"),
    [WAPP_TERM_COLOUR_FG_BR_MAGENTA] = wapp_str8_lit_ro_initialiser_list("\033[95m"),
    [WAPP_TERM_COLOUR_FG_BR_YELLOW]  = wapp_str8_lit_ro_initialiser_list("\033[93m"),
    [WAPP_TERM_COLOUR_FG_BR_WHITE]   = wapp_str8_lit_ro_initialiser_list("\033[97m"),
    [WAPP_TERM_COLOUR_CLEAR]         = wapp_str8_lit_ro_initialiser_list("\033[0m"),
};

void print_coloured_text(Str8RO *text, TerminalColour colour) {
  printf(WAPP_STR8_SPEC WAPP_STR8_SPEC, wapp_str8_varg(colours[colour]), wapp_str8_varg((*text)));
}

#endif // !WAPP_PLATFORM_POSIX
