#include "console.h"

// looks like it is going to be platform-dependent...

#include <conio.h>
#include <windows.h>
#include <winbase.h>
#include <wincon.h>


namespace cryptrav
{

namespace Console
{



int            getKey(void)
{
 return        getch();
}


void           setTextAttr(quint8 textColor, quint8 backColor)
{
 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textColor | (backColor << 4));
}


QString        getLine(quint8 textColor, quint8 backColor)
{
 QTextStream   qStdIn(stdin, QIODevice::ReadOnly);
 QString       qStr;

 setTextAttr(textColor, backColor);
 do qStr = qStdIn.readLine(); while (qStr.isEmpty());
 setTextAttr(TEXTCOLOR_DEFAULT, BACKCOLOR_DEFAULT);

 return qStr;
}


void           put(QString qStr, quint8 textColor, quint8 backColor)
{
 QTextStream   qStdOut(stdout, QIODevice::WriteOnly);

 setTextAttr(textColor, backColor);
 qStdOut << qStr;
 setTextAttr(TEXTCOLOR_DEFAULT, BACKCOLOR_DEFAULT);
}

void           putLine(QString qStr, quint8 textColor, quint8 backColor)
{
 QTextStream   qStdOut(stdout, QIODevice::WriteOnly);

 setTextAttr(textColor, backColor);
 qStdOut << qStr << endl;
 setTextAttr(TEXTCOLOR_DEFAULT, BACKCOLOR_DEFAULT);
}


void           putSuccess(bool state)
{
 if (state)
  putLine("Done", EGA_GREEN);
   else
  putLine("Failed", EGA_LIGHTRED);

}

void           putHelp(QString qStr, quint8 textColor, quint8 backColor)
{
 putLine(qStr, textColor, backColor);
}

void           putUnknown(QString qStr, quint8 textColor, quint8 backColor)
{
 putLine(qStr, textColor, backColor);
}


} // namespace "Console"

} // namespace "cryptrav"
