diff options
| author | Martin Hořeňovský | 2022-03-21 00:22:54 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-03-24 16:02:51 +0100 |
| commit | 4d8acafecb973d9b03178346c3f1566fe7485fb1 (patch) | |
| tree | 9d3ffd8440bdc530785e81e1a140c0738d9e8f8c /src/catch2/internal | |
| parent | cf6dd937ab2ff62d29b34d62411cfd03d3822021 (diff) | |
| download | catch3-4d8acafecb973d9b03178346c3f1566fe7485fb1.tar.gz | |
Rename isStdout => isConsole and add doccomment
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_console_colour.cpp | 4 | ||||
| -rw-r--r-- | src/catch2/internal/catch_stream.cpp | 4 | ||||
| -rw-r--r-- | src/catch2/internal/catch_stream.hpp | 15 |
3 files changed, 16 insertions, 7 deletions
diff --git a/src/catch2/internal/catch_console_colour.cpp b/src/catch2/internal/catch_console_colour.cpp index fcfd953c..7f294abc 100644 --- a/src/catch2/internal/catch_console_colour.cpp +++ b/src/catch2/internal/catch_console_colour.cpp @@ -97,7 +97,7 @@ namespace { // Win32 text colour APIs can only be used on console streams // We cannot check that the output hasn't been redirected, // so we just check that the original stream is console stream. - return stream.isStdout(); + return stream.isConsole(); } private: @@ -164,7 +164,7 @@ namespace { // only want to use the colours if we are writing to console. // However, console might be redirected, so we make an attempt at // checking for that on platforms where we know how to do that. - bool useColour = stream.isStdout(); + bool useColour = stream.isConsole(); #if defined( CATCH_INTERNAL_HAS_ISATTY ) && \ !( defined( __DJGPP__ ) && defined( __STRICT_ANSI__ ) ) ErrnoGuard _; // for isatty diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp index a5aecf8e..dfa322c7 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_stream.cpp @@ -99,7 +99,7 @@ namespace Detail { public: // IStream std::ostream& stream() const override { return m_os; } - bool isStdout() const override { return true; } + bool isConsole() const override { return true; } }; class CerrStream : public IStream { @@ -113,7 +113,7 @@ namespace Detail { public: // IStream std::ostream& stream() const override { return m_os; } - bool isStdout() const override { return true; } + bool isConsole() const override { return true; } }; /////////////////////////////////////////////////////////////////////////// diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp index 1b92b4dc..ba0a3876 100644 --- a/src/catch2/internal/catch_stream.hpp +++ b/src/catch2/internal/catch_stream.hpp @@ -26,9 +26,18 @@ namespace Catch { public: virtual ~IStream(); // = default virtual std::ostream& stream() const = 0; - // Win32 colour supports requires us to identify whether a stream - // is backed by stdout (so we can colour it) or not (and we can't). - virtual bool isStdout() const { return false; } + /** + * Best guess on whether the instance is writing to a console (e.g. via stdout/stderr) + * + * This is useful for e.g. Win32 colour support, because the Win32 + * API manipulates console directly, unlike POSIX escape codes, + * that can be written anywhere. + * + * Due to variety of ways to change where the stdout/stderr is + * _actually_ being written, users should always assume that + * the answer might be wrong. + */ + virtual bool isConsole() const { return false; } }; auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream const>; |