MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / ShouldUseColor

Function ShouldUseColor

cpp/test/src/gtest.cc:2913–2947  ·  view source on GitHub ↗

Returns true iff Google Test should use colors in the output.

Source from the content-addressed store, hash-verified

2911
2912// Returns true iff Google Test should use colors in the output.
2913bool ShouldUseColor(bool stdout_is_tty) {
2914 const char* const gtest_color = GTEST_FLAG(color).c_str();
2915
2916 if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
2917#if GTEST_OS_WINDOWS
2918 // On Windows the TERM variable is usually not set, but the
2919 // console there does support colors.
2920 return stdout_is_tty;
2921#else
2922 // On non-Windows platforms, we rely on the TERM variable.
2923 const char* const term = posix::GetEnv("TERM");
2924 const bool term_supports_color =
2925 String::CStringEquals(term, "xterm") ||
2926 String::CStringEquals(term, "xterm-color") ||
2927 String::CStringEquals(term, "xterm-256color") ||
2928 String::CStringEquals(term, "screen") ||
2929 String::CStringEquals(term, "screen-256color") ||
2930 String::CStringEquals(term, "tmux") ||
2931 String::CStringEquals(term, "tmux-256color") ||
2932 String::CStringEquals(term, "rxvt-unicode") ||
2933 String::CStringEquals(term, "rxvt-unicode-256color") ||
2934 String::CStringEquals(term, "linux") ||
2935 String::CStringEquals(term, "cygwin");
2936 return stdout_is_tty && term_supports_color;
2937#endif // GTEST_OS_WINDOWS
2938 }
2939
2940 return String::CaseInsensitiveCStringEquals(gtest_color, "yes") ||
2941 String::CaseInsensitiveCStringEquals(gtest_color, "true") ||
2942 String::CaseInsensitiveCStringEquals(gtest_color, "t") ||
2943 String::CStringEquals(gtest_color, "1");
2944 // We take "yes", "true", "t", and "1" as meaning "yes". If the
2945 // value is neither one of these nor "auto", we treat it as "no" to
2946 // be conservative.
2947}
2948
2949// Helpers for printing colored strings to stdout. Note that on Windows, we
2950// cannot simply emit special characters and have the terminal change colors.

Callers 1

ColoredPrintfFunction · 0.85

Calls 2

GetEnvFunction · 0.85
c_strMethod · 0.45

Tested by

no test coverage detected