Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2016-02-24 18:51:01 +0000
committerPhil Nash2016-02-29 08:03:48 +0000
commit8ccb18daa9c380c35ae4d13751e2a1aeed905815 (patch)
tree5d96d80991cdfb35d8bd4d0880fb932b51a89874 /include
parentdce21544746dd73903eb13482775207662e161d4 (diff)
downloadcatch3-8ccb18daa9c380c35ae4d13751e2a1aeed905815.tar.gz
Added --use-colour option to give finer control over colourisation.
--force-colour is still present but deprecated (will remove in v2)
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_commandline.hpp25
-rw-r--r--include/internal/catch_config.hpp8
-rw-r--r--include/internal/catch_console_colour_impl.hpp26
-rw-r--r--include/internal/catch_interfaces_config.h7
4 files changed, 53 insertions, 13 deletions
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index 640b304d..6926559a 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -62,6 +62,21 @@ namespace Catch {
? ShowDurations::Always
: ShowDurations::Never;
}
+ inline void setUseColour( ConfigData& config, std::string const& value ) {
+ std::string mode = toLower( value );
+
+ if( mode == "yes" )
+ config.useColour = UseColour::Yes;
+ else if( mode == "no" )
+ config.useColour = UseColour::No;
+ else if( mode == "auto" )
+ config.useColour = UseColour::Auto;
+ else
+ throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
+ }
+ inline void forceColour( ConfigData& config ) {
+ config.useColour = UseColour::Yes;
+ }
inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
std::ifstream f( _filename.c_str() );
if( !f.is_open() )
@@ -148,7 +163,7 @@ namespace Catch {
cli["-d"]["--durations"]
.describe( "show test durations" )
- .bind( &setShowDurations, "yes/no" );
+ .bind( &setShowDurations, "yes|no" );
cli["-f"]["--input-file"]
.describe( "load test names to run from a file" )
@@ -176,8 +191,12 @@ namespace Catch {
.bind( &setRngSeed, "'time'|number" );
cli["--force-colour"]
- .describe( "force colourised output" )
- .bind( &ConfigData::forceColour );
+ .describe( "force colourised output (deprecated)" )
+ .bind( &forceColour );
+
+ cli["--use-colour"]
+ .describe( "should output be colourised" )
+ .bind( &setUseColour, "yes|no" );
return cli;
}
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index a09210cb..2665f474 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -37,14 +37,14 @@ namespace Catch {
noThrow( false ),
showHelp( false ),
showInvisibles( false ),
- forceColour( false ),
filenamesAsTags( false ),
abortAfter( -1 ),
rngSeed( 0 ),
verbosity( Verbosity::Normal ),
warnings( WarnAbout::Nothing ),
showDurations( ShowDurations::DefaultForReporter ),
- runOrder( RunTests::InDeclarationOrder )
+ runOrder( RunTests::InDeclarationOrder ),
+ useColour( UseColour::Auto )
{}
bool listTests;
@@ -57,7 +57,6 @@ namespace Catch {
bool noThrow;
bool showHelp;
bool showInvisibles;
- bool forceColour;
bool filenamesAsTags;
int abortAfter;
@@ -67,6 +66,7 @@ namespace Catch {
WarnAbout::What warnings;
ShowDurations::OrNot showDurations;
RunTests::InWhatOrder runOrder;
+ UseColour::YesOrNo useColour;
std::string outputFilename;
std::string name;
@@ -133,7 +133,7 @@ namespace Catch {
virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; }
virtual unsigned int rngSeed() const { return m_data.rngSeed; }
- virtual bool forceColour() const { return m_data.forceColour; }
+ virtual UseColour::YesOrNo useColour() const { return m_data.useColour; }
private:
diff --git a/include/internal/catch_console_colour_impl.hpp b/include/internal/catch_console_colour_impl.hpp
index 9ca915ff..f776952b 100644
--- a/include/internal/catch_console_colour_impl.hpp
+++ b/include/internal/catch_console_colour_impl.hpp
@@ -95,7 +95,18 @@ namespace {
IColourImpl* platformColourInstance() {
static Win32ColourImpl s_instance;
- return &s_instance;
+
+ Ptr<IConfig const> config = getCurrentContext().getConfig();
+ UseColour::YesOrNo colourMode = config
+ ? config->useColour()
+ : UseColour::Auto;
+ if( colourMode == UseColour::Auto )
+ colourMode = !isDebuggerActive()
+ ? UseColour::Yes
+ : UseColour::No;
+ return colourMode == UseColour::Yes
+ ? &s_instance
+ : NoColourImpl::instance();
}
} // end anon namespace
@@ -146,7 +157,14 @@ namespace {
IColourImpl* platformColourInstance() {
Ptr<IConfig const> config = getCurrentContext().getConfig();
- return (config && config->forceColour()) || isatty(STDOUT_FILENO)
+ UseColour::YesOrNo colourMode = config
+ ? config->useColour()
+ : UseColour::Auto;
+ if( colourMode == UseColour::Auto )
+ colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
+ ? UseColour::Yes
+ : UseColour::No;
+ return colourMode == UseColour::Yes
? PosixColourImpl::instance()
: NoColourImpl::instance();
}
@@ -171,9 +189,7 @@ namespace Catch {
Colour::~Colour(){ if( !m_moved ) use( None ); }
void Colour::use( Code _colourCode ) {
- static IColourImpl* impl = isDebuggerActive()
- ? NoColourImpl::instance()
- : platformColourInstance();
+ static IColourImpl* impl = platformColourInstance();
impl->use( _colourCode );
}
diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h
index 1281bd7e..17914b4e 100644
--- a/include/internal/catch_interfaces_config.h
+++ b/include/internal/catch_interfaces_config.h
@@ -37,6 +37,11 @@ namespace Catch {
InLexicographicalOrder,
InRandomOrder
}; };
+ struct UseColour { enum YesOrNo {
+ Auto,
+ Yes,
+ No
+ }; };
class TestSpec;
@@ -56,7 +61,7 @@ namespace Catch {
virtual TestSpec const& testSpec() const = 0;
virtual RunTests::InWhatOrder runOrder() const = 0;
virtual unsigned int rngSeed() const = 0;
- virtual bool forceColour() const = 0;
+ virtual UseColour::YesOrNo useColour() const = 0;
};
}