Merge "Only use color in supported terminal."
am: 9842db42e9
Change-Id: Id7970786ad9b17847cc8085bf44c25dc47f5178a
This commit is contained in:
commit
eeb0210cf0
1 changed files with 28 additions and 4 deletions
|
@ -78,15 +78,39 @@ static constexpr const char* COLOR_RED = "\033[0;31m";
|
|||
static constexpr const char* COLOR_GREEN = "\033[0;32m";
|
||||
static constexpr const char* COLOR_YELLOW = "\033[0;33m";
|
||||
|
||||
static void ColoredPrintf(const char* const color, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
static bool ShouldUseColor() {
|
||||
bool stdout_is_tty = isatty(STDOUT_FILENO) != 0;
|
||||
if (!stdout_is_tty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& gtest_color = ::testing::GTEST_FLAG(color);
|
||||
if (gtest_color == "yes" || gtest_color == "true" || gtest_color == "t") {
|
||||
return true;
|
||||
}
|
||||
if (gtest_color != "auto") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* const term = getenv("COLORTERM");
|
||||
return term != nullptr && term[0] != 0;
|
||||
}
|
||||
|
||||
static void ColoredPrintf(const char* const color, const char* fmt, ...) {
|
||||
static const bool use_color = ShouldUseColor();
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
if (!use_color) {
|
||||
vprintf(fmt, args);
|
||||
} else {
|
||||
printf("%s", color);
|
||||
vprintf(fmt, args);
|
||||
printf("%s", COLOR_RESET);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
constexpr int DEFAULT_GLOBAL_TEST_RUN_DEADLINE_MS = 90000;
|
||||
|
|
Loading…
Reference in a new issue