Returns true iff Google Test should use colors in the output.
| 3886 | |
| 3887 | // Returns true iff Google Test should use colors in the output. |
| 3888 | bool ShouldUseColor(bool stdout_is_tty) { |
| 3889 | const char* const gtest_color = GTEST_FLAG(color).c_str(); |
| 3890 | |
| 3891 | if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) { |
| 3892 | #if GTEST_OS_WINDOWS |
| 3893 | // On Windows the TERM variable is usually not set, but the |
| 3894 | // console there does support colors. |
| 3895 | return stdout_is_tty; |
| 3896 | #else |
| 3897 | // On non-Windows platforms, we rely on the TERM variable. |
| 3898 | const char* const term = posix::GetEnv("TERM"); |
| 3899 | const bool term_supports_color = |
| 3900 | String::CStringEquals(term, "xterm") || |
| 3901 | String::CStringEquals(term, "xterm-color") || |
| 3902 | String::CStringEquals(term, "xterm-256color") || |
| 3903 | String::CStringEquals(term, "screen") || |
| 3904 | String::CStringEquals(term, "linux") || |
| 3905 | String::CStringEquals(term, "cygwin"); |
| 3906 | return stdout_is_tty && term_supports_color; |
| 3907 | #endif // GTEST_OS_WINDOWS |
| 3908 | } |
| 3909 | |
| 3910 | return String::CaseInsensitiveCStringEquals(gtest_color, "yes") || |
| 3911 | String::CaseInsensitiveCStringEquals(gtest_color, "true") || |
| 3912 | String::CaseInsensitiveCStringEquals(gtest_color, "t") || |
| 3913 | String::CStringEquals(gtest_color, "1"); |
| 3914 | // We take "yes", "true", "t", and "1" as meaning "yes". If the |
| 3915 | // value is neither one of these nor "auto", we treat it as "no" to |
| 3916 | // be conservative. |
| 3917 | } |
| 3918 | |
| 3919 | // Helpers for printing colored strings to stdout. Note that on Windows, we |
| 3920 | // cannot simply emit special characters and have the terminal change colors. |
no test coverage detected