#include "pxheaders.h"
#include "colorfulclientuser.h"
void ColorfulClientUser::Message(Error *err)
{
StrBuf b;
err->Fmt(b, EF_NEWLINE);
const char* text = b.Text();
if (err->IsWarning())
{
printText(warnColor, text);
}
else if (err->IsInfo())
{
printText(infoColor, text);
}
else
{
printText(erroColor, text);
}
}
/*
0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White
*/
WORD ColorfulClientUser::getColor(char colorCharacter)
{
switch (colorCharacter)
{
case '0':
return 0x0000;
break;
case '1':
return 0x0001;
break;
case '2':
return 0x0002;
break;
case '3':
return 0x0003;
break;
case '4':
return 0x0004;
break;
case '5':
return 0x0005;
break;
case '6':
return 0x0006;
break;
case '7':
return 0x0007;
break;
case '8':
return 0x0008;
break;
case '9':
return 0x0009;
break;
case 'A':
return 0x000A;
break;
case 'B':
return 0x000B;
break;
case 'C':
return 0x000C;
break;
case 'D':
return 0x000D;
break;
case 'E':
return 0x000E;
break;
case 'F':
return 0x000F;
break;
}
return 0x000F;
}
void ColorfulClientUser::printText(WORD color, const char* text)
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes ;
WORD newColor = (wOldColorAttrs & 0xFFF0) | color;
SetConsoleTextAttribute ( h, newColor ) ; //Set the new color information
printf(text);
SetConsoleTextAttribute ( h, wOldColorAttrs ); //Set the new color information
}