mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-23 05:46:11 +01:00
Added SecondaryText colour enum
- slightly refactored ConsoleColour as well
This commit is contained in:
parent
9d15d36748
commit
c7e602f3f2
@ -24,7 +24,9 @@ namespace Catch {
|
|||||||
Success,
|
Success,
|
||||||
|
|
||||||
OriginalExpression,
|
OriginalExpression,
|
||||||
ReconstructedExpression
|
ReconstructedExpression,
|
||||||
|
|
||||||
|
SecondaryText
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void set( Colours colour ) = 0;
|
virtual void set( Colours colour ) = 0;
|
||||||
|
@ -18,21 +18,23 @@ namespace {
|
|||||||
using namespace Catch;
|
using namespace Catch;
|
||||||
|
|
||||||
WORD mapConsoleColour( IConsoleColourCodes::Colours colour ) {
|
WORD mapConsoleColour( IConsoleColourCodes::Colours colour ) {
|
||||||
|
enum Win32Colours {
|
||||||
|
Grey = FOREGROUND_INTENSITY,
|
||||||
|
BrightRed = FOREGROUND_RED | FOREGROUND_INTENSITY,
|
||||||
|
BrightGreen = FOREGROUND_GREEN | FOREGROUND_INTENSITY,
|
||||||
|
DarkGreen = FOREGROUND_GREEN,
|
||||||
|
Turquoise = FOREGROUND_BLUE | FOREGROUND_GREEN,
|
||||||
|
Yellow = FOREGROUND_RED | FOREGROUND_GREEN
|
||||||
|
};
|
||||||
switch( colour ) {
|
switch( colour ) {
|
||||||
case IConsoleColourCodes::FileName:
|
case IConsoleColourCodes::FileName: return Grey;
|
||||||
return FOREGROUND_INTENSITY; // greyed out
|
case IConsoleColourCodes::ResultError: return BrightRed;
|
||||||
case IConsoleColourCodes::ResultError:
|
case IConsoleColourCodes::ResultSuccess: return BrightGreen;
|
||||||
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
case IConsoleColourCodes::Error: return BrightRed;
|
||||||
case IConsoleColourCodes::ResultSuccess:
|
case IConsoleColourCodes::Success: return DarkGreen;
|
||||||
return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green
|
case IConsoleColourCodes::OriginalExpression: return Turquoise;
|
||||||
case IConsoleColourCodes::Error:
|
case IConsoleColourCodes::ReconstructedExpression: return Yellow;
|
||||||
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
case IConsoleColourCodes::SecondaryText: return Grey;
|
||||||
case IConsoleColourCodes::Success:
|
|
||||||
return FOREGROUND_GREEN; // dark green
|
|
||||||
case IConsoleColourCodes::OriginalExpression:
|
|
||||||
return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise
|
|
||||||
case IConsoleColourCodes::ReconstructedExpression:
|
|
||||||
return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow
|
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,39 +83,36 @@ namespace {
|
|||||||
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
||||||
// https://github.com/philsquared/Catch/pull/131
|
// https://github.com/philsquared/Catch/pull/131
|
||||||
|
|
||||||
|
const char* WhiteOrNormal = "[0m";
|
||||||
|
const char* BoldRed = "[1;31m";
|
||||||
|
const char* BoldGreen = "[1;32m";
|
||||||
|
const char* Green = "[0;32m";
|
||||||
|
const char* Cyan = "[0;36m";
|
||||||
|
const char* Yellow = "[0;33m";
|
||||||
|
const char* LightGrey = "[0;37m";
|
||||||
|
|
||||||
struct AnsiConsoleColourCodes : IConsoleColourCodes {
|
struct AnsiConsoleColourCodes : IConsoleColourCodes {
|
||||||
|
|
||||||
~AnsiConsoleColourCodes() {
|
~AnsiConsoleColourCodes() {
|
||||||
set( None );
|
set( None );
|
||||||
}
|
}
|
||||||
|
|
||||||
void set( Colours colour ) {
|
const char* escapeCodeForColour( Colours colour ) {
|
||||||
const char colourEscape = '\033';
|
|
||||||
switch( colour ) {
|
switch( colour ) {
|
||||||
case FileName:
|
case FileName: return WhiteOrNormal;
|
||||||
std::cout << colourEscape << "[0m"; // white/ normal
|
case ResultError: return BoldRed;
|
||||||
break;
|
case ResultSuccess: return BoldGreen;
|
||||||
case ResultError:
|
case Error: return BoldRed;
|
||||||
std::cout << colourEscape << "[1;31m"; // bold red
|
case Success: return Green;
|
||||||
break;
|
case OriginalExpression: return Cyan;
|
||||||
case ResultSuccess:
|
case ReconstructedExpression: return Yellow;
|
||||||
std::cout << colourEscape << "[1;32m"; // bold green
|
case SecondaryText: return LightGrey;
|
||||||
break;
|
case None: return WhiteOrNormal;
|
||||||
case Error:
|
}
|
||||||
std::cout << colourEscape << "[1;31m"; // bold red
|
}
|
||||||
break;
|
|
||||||
case Success:
|
void set( Colours colour ) {
|
||||||
std::cout << colourEscape << "[0;32m"; // green
|
std::cout << '\033' << escapeCodeForColour( colour );
|
||||||
break;
|
|
||||||
case OriginalExpression:
|
|
||||||
std::cout << colourEscape << "[0;36m"; // cyan
|
|
||||||
break;
|
|
||||||
case ReconstructedExpression:
|
|
||||||
std::cout << colourEscape << "[0;33m"; // yellow
|
|
||||||
break;
|
|
||||||
case None:
|
|
||||||
std::cout << colourEscape << "[0m"; // reset
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user