File indexing completed on 2025-01-18 09:54:05
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_CONSOLE_COLOUR_HPP_INCLUDED
0009 #define CATCH_CONSOLE_COLOUR_HPP_INCLUDED
0010
0011 #include <catch2/internal/catch_unique_ptr.hpp>
0012
0013 #include <iosfwd>
0014 #include <cstdint>
0015
0016 namespace Catch {
0017
0018 enum class ColourMode : std::uint8_t;
0019 class IStream;
0020
0021 struct Colour {
0022 enum Code {
0023 None = 0,
0024
0025 White,
0026 Red,
0027 Green,
0028 Blue,
0029 Cyan,
0030 Yellow,
0031 Grey,
0032
0033 Bright = 0x10,
0034
0035 BrightRed = Bright | Red,
0036 BrightGreen = Bright | Green,
0037 LightGrey = Bright | Grey,
0038 BrightWhite = Bright | White,
0039 BrightYellow = Bright | Yellow,
0040
0041
0042 FileName = LightGrey,
0043 Warning = BrightYellow,
0044 ResultError = BrightRed,
0045 ResultSuccess = BrightGreen,
0046 ResultExpectedFailure = Warning,
0047
0048 Error = BrightRed,
0049 Success = Green,
0050 Skip = LightGrey,
0051
0052 OriginalExpression = Cyan,
0053 ReconstructedExpression = BrightYellow,
0054
0055 SecondaryText = LightGrey,
0056 Headers = White
0057 };
0058 };
0059
0060 class ColourImpl {
0061 protected:
0062
0063 IStream* m_stream;
0064 public:
0065 ColourImpl( IStream* stream ): m_stream( stream ) {}
0066
0067
0068
0069 class ColourGuard {
0070 ColourImpl const* m_colourImpl;
0071 Colour::Code m_code;
0072 bool m_engaged = false;
0073
0074 public:
0075
0076 ColourGuard( Colour::Code code,
0077 ColourImpl const* colour );
0078
0079 ColourGuard( ColourGuard const& rhs ) = delete;
0080 ColourGuard& operator=( ColourGuard const& rhs ) = delete;
0081
0082 ColourGuard( ColourGuard&& rhs ) noexcept;
0083 ColourGuard& operator=( ColourGuard&& rhs ) noexcept;
0084
0085
0086 ~ColourGuard();
0087
0088
0089
0090
0091
0092
0093 ColourGuard& engage( std::ostream& stream ) &;
0094
0095
0096
0097
0098
0099 ColourGuard&& engage( std::ostream& stream ) &&;
0100
0101 private:
0102
0103 friend std::ostream& operator<<( std::ostream& lhs,
0104 ColourGuard& guard ) {
0105 guard.engageImpl( lhs );
0106 return lhs;
0107 }
0108
0109 friend std::ostream& operator<<( std::ostream& lhs,
0110 ColourGuard&& guard) {
0111 guard.engageImpl( lhs );
0112 return lhs;
0113 }
0114
0115 void engageImpl( std::ostream& stream );
0116
0117 };
0118
0119 virtual ~ColourImpl();
0120
0121
0122
0123
0124
0125
0126 ColourGuard guardColour( Colour::Code colourCode );
0127
0128 private:
0129 virtual void use( Colour::Code colourCode ) const = 0;
0130 };
0131
0132
0133 Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
0134 IStream* stream );
0135
0136
0137 bool isColourImplAvailable( ColourMode colourSelection );
0138
0139 }
0140
0141 #endif