MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / ShouldUseColor

Function ShouldUseColor

tests/gtest/gtest-all.cc:4482–4516  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

4480
4481// Returns true iff Google Test should use colors in the output.
4482bool ShouldUseColor(bool stdout_is_tty) {
4483 const char* const gtest_color = GTEST_FLAG(color).c_str();
4484
4485 if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
4486#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
4487 // On Windows the TERM variable is usually not set, but the
4488 // console there does support colors.
4489 return stdout_is_tty;
4490#else
4491 // On non-Windows platforms, we rely on the TERM variable.
4492 const char* const term = posix::GetEnv("TERM");
4493 const bool term_supports_color =
4494 String::CStringEquals(term, "xterm") ||
4495 String::CStringEquals(term, "xterm-color") ||
4496 String::CStringEquals(term, "xterm-256color") ||
4497 String::CStringEquals(term, "screen") ||
4498 String::CStringEquals(term, "screen-256color") ||
4499 String::CStringEquals(term, "tmux") ||
4500 String::CStringEquals(term, "tmux-256color") ||
4501 String::CStringEquals(term, "rxvt-unicode") ||
4502 String::CStringEquals(term, "rxvt-unicode-256color") ||
4503 String::CStringEquals(term, "linux") ||
4504 String::CStringEquals(term, "cygwin");
4505 return stdout_is_tty && term_supports_color;
4506#endif // GTEST_OS_WINDOWS
4507 }
4508
4509 return String::CaseInsensitiveCStringEquals(gtest_color, "yes") ||
4510 String::CaseInsensitiveCStringEquals(gtest_color, "true") ||
4511 String::CaseInsensitiveCStringEquals(gtest_color, "t") ||
4512 String::CStringEquals(gtest_color, "1");
4513 // We take "yes", "true", "t", and "1" as meaning "yes". If the
4514 // value is neither one of these nor "auto", we treat it as "no" to
4515 // be conservative.
4516}
4517
4518// Helpers for printing colored strings to stdout. Note that on Windows, we
4519// cannot simply emit special characters and have the terminal change colors.

Callers 1

ColoredPrintfFunction · 0.85

Calls 1

GetEnvFunction · 0.85

Tested by

no test coverage detected