mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Added terminal colour codes for POSIX
With thanks to Adam Strzelecki
This commit is contained in:
parent
8f4cc541d5
commit
108f1937d8
@ -10,12 +10,57 @@
|
||||
|
||||
#include "catch_console_colour.hpp"
|
||||
|
||||
#ifdef CATCH_PLATFORM_WINDOWS
|
||||
namespace Catch {
|
||||
|
||||
#if defined( CATCH_CONFIG_USE_POSIX_COLOUR_CODES )
|
||||
|
||||
// use POSIX console terminal codes
|
||||
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
||||
// https://github.com/philsquared/Catch/pull/131
|
||||
|
||||
TextColour::TextColour( Colours colour ) {
|
||||
if( colour )
|
||||
set( colour );
|
||||
}
|
||||
|
||||
TextColour::~TextColour() {
|
||||
set( TextColour::None );
|
||||
}
|
||||
|
||||
void TextColour::set( Colours colour ) {
|
||||
if( isatty( fileno(stdout) ) ) {
|
||||
switch( colour ) {
|
||||
case TextColour::FileName:
|
||||
std::cout << "\e[1m"; // bold
|
||||
break;
|
||||
case TextColour::ResultError:
|
||||
std::cout << "\e[1;31m"; // bright red
|
||||
break;
|
||||
case TextColour::ResultSuccess:
|
||||
std::cout << "\e[1;32m"; // bright green
|
||||
break;
|
||||
case TextColour::Error:
|
||||
std::cout << "\e[0;31m"; // dark red
|
||||
break;
|
||||
case TextColour::Success:
|
||||
std::cout << "\e[0;32m"; // dark green
|
||||
break;
|
||||
case TextColour::OriginalExpression:
|
||||
std::cout << "\e[0;36m"; // cyan
|
||||
break;
|
||||
case TextColour::ReconstructedExpression:
|
||||
std::cout << "\e[0;33m"; // yellow
|
||||
break;
|
||||
case TextColour::None:
|
||||
std::cout << "\e[0m"; // reset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined ( CATCH_PLATFORM_WINDOWS )
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
namespace {
|
||||
|
||||
WORD mapConsoleColour( TextColour::Colours colour ) {
|
||||
@ -79,17 +124,14 @@ namespace Catch {
|
||||
m_impl->set( colour );
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#else
|
||||
|
||||
namespace Catch {
|
||||
TextColour::TextColour( Colours ){}
|
||||
TextColour::~TextColour(){}
|
||||
void TextColour::set( Colours ){}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
||||
|
Loading…
Reference in New Issue
Block a user