Skip to content

Instantly share code, notes, and snippets.

@melihovv
Last active August 29, 2015 14:27
Show Gist options
  • Save melihovv/57cd75906c6a717a6499 to your computer and use it in GitHub Desktop.
Save melihovv/57cd75906c6a717a6499 to your computer and use it in GitHub Desktop.
Qt Tests Colorifier
#include <windows.h>
#include <iostream>
#include <string>
#include <regex>
enum Color
{
blue = 1, green, cyan, red, purple, yellow, grey, dgrey, hblue, hgreen, hcyan, hred, hpurple, hyellow, hwhite
};
using namespace std;
void SetConsoleColor(Color color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (WORD) color);
}
WORD GetConsoleColor()
{
auto consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO con_info;
GetConsoleScreenBufferInfo(consoleHandle, &con_info);
return con_info.wAttributes;
}
class ColorGuard
{
public:
ColorGuard() : m_color(GetConsoleColor())
{
}
~ColorGuard()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), m_color);
}
private:
WORD m_color;
};
int main()
{
string line;
regex fail("(FAIL.*)");
regex pass("(PASS.*)");
while (getline(cin, line))
{
ColorGuard guard;
if (regex_match(line, fail))
{
SetConsoleColor(hred);
}
if (regex_match(line, pass))
{
SetConsoleColor(hgreen);
}
cout << line << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment