// (c) 2005-2007 Electronic Arts Inc.

#ifdef _MSC_VER
#include <stdio.h>
#include <io.h>
#include <windows.h>
#include <string.h>



//----------------------------------------------------------------------------------------
// console colours
// 0  nothing
// 1  bold
// 2  underline
// 3  blink
// 4  inverse video
// 5  hide
void ConColour(char * foreground, char * background, int mod)
{
    int i = 0;
    int fore = 7;
    int back = 0;
    int mods[]  = {0,FOREGROUND_INTENSITY,COMMON_LVB_UNDERSCORE,0,COMMON_LVB_REVERSE_VIDEO,0};
    int fore_colours[] = {0,FOREGROUND_RED,FOREGROUND_GREEN,FOREGROUND_GREEN|FOREGROUND_RED,FOREGROUND_BLUE,
                              FOREGROUND_BLUE|FOREGROUND_RED,FOREGROUND_BLUE|FOREGROUND_GREEN,FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN};
    int back_colours[] = {0,BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_GREEN|BACKGROUND_RED,BACKGROUND_BLUE,
                              BACKGROUND_BLUE|BACKGROUND_RED,BACKGROUND_BLUE|BACKGROUND_GREEN,BACKGROUND_BLUE|BACKGROUND_RED|BACKGROUND_GREEN};
    char * colours[]     = {"black","red","green","yellow","blue","magenta","cyan","white"};

    if(mod > 5 || mod < 0)
        mod = 0;
    for(i = 0; i < 8;i++)
    {
        if(!strcmp(foreground,colours[i]))
            fore = i;
        if(!strcmp(background,colours[i]))
            back = i;
    }
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),(WORD)(back_colours[back]|fore_colours[fore]|mods[mod]));
}
#else
void ConColour(char * foreground,char * background,int mod)
{
    return;
}
#endif
