11# pragma clang diagnostic push
12# pragma clang diagnostic ignored "-Wexit-time-destructors"
32 virtual ~IColourImpl() =
default;
36 struct NoColourImpl : IColourImpl {
39 static IColourImpl* instance() {
40 static NoColourImpl s_instance;
48#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
49# ifdef CATCH_PLATFORM_WINDOWS
50# define CATCH_CONFIG_COLOUR_WINDOWS
52# define CATCH_CONFIG_COLOUR_ANSI
57#if defined ( CATCH_CONFIG_COLOUR_WINDOWS )
62 class Win32ColourImpl :
public IColourImpl {
64 Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
66 CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
67 GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
68 originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
69 originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
72 void use( Colour::Code _colourCode )
override {
73 switch( _colourCode ) {
74 case Colour::None:
return setTextAttribute( originalForegroundAttributes );
75 case Colour::White:
return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
76 case Colour::Red:
return setTextAttribute( FOREGROUND_RED );
77 case Colour::Green:
return setTextAttribute( FOREGROUND_GREEN );
78 case Colour::Blue:
return setTextAttribute( FOREGROUND_BLUE );
79 case Colour::Cyan:
return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
80 case Colour::Yellow:
return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
81 case Colour::Grey:
return setTextAttribute( 0 );
83 case Colour::LightGrey:
return setTextAttribute( FOREGROUND_INTENSITY );
84 case Colour::BrightRed:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
85 case Colour::BrightGreen:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
86 case Colour::BrightWhite:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
87 case Colour::BrightYellow:
return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN );
97 void setTextAttribute( WORD _textAttribute ) {
98 SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
101 WORD originalForegroundAttributes;
102 WORD originalBackgroundAttributes;
105 IColourImpl* platformColourInstance() {
106 static Win32ColourImpl s_instance;
116 : NoColourImpl::instance();
122#elif defined( CATCH_CONFIG_COLOUR_ANSI )
133 class PosixColourImpl :
public IColourImpl {
136 switch( _colourCode ) {
156 static IColourImpl* instance() {
157 static PosixColourImpl s_instance;
162 void setColour(
const char* _escapeCode ) {
164 <<
'\033' << _escapeCode;
168 bool useColourOnPlatform() {
170#ifdef CATCH_PLATFORM_MAC
173#if !(defined(__DJGPP__) && defined(__STRICT_ANSI__))
174 isatty(STDOUT_FILENO)
180 IColourImpl* platformColourInstance() {
187 colourMode = useColourOnPlatform()
191 ? PosixColourImpl::instance()
192 : NoColourImpl::instance();
202 static IColourImpl* platformColourInstance() {
return NoColourImpl::instance(); }
212 m_moved = rhs.m_moved;
216 m_moved = rhs.m_moved;
224 static IColourImpl* impl = platformColourInstance();
225 impl->use( _colourCode );
234#if defined(__clang__)
235# pragma clang diagnostic pop
#define CATCH_INTERNAL_ERROR(msg)
IContext & getCurrentContext()
std::shared_ptr< IConfig const > IConfigPtr
auto operator<<(std::ostream &os, LazyExpression const &lazyExpr) -> std::ostream &
static void use(Code _colourCode)
Colour & operator=(Colour &&other) noexcept
virtual IConfigPtr const & getConfig() const =0