From 0b61a17c93d131cbd43222285d718156f79439ac Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 22 May 2025 11:20:56 -0400 Subject: [PATCH] ctest: Enable color output on Windows Consoles supporting VT100 escapes Extend commit ffdec37a19 (CTest: Add colored output on tests summary where supported, 2018-11-07, v3.14.0-rc1~384^2) to enable color on Windows. Issue: #26924 --- Source/cmCTest.cxx | 34 ++++------------------------------ Source/cmCTest.h | 5 ----- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 206dae0bdb..f6c05360c8 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -34,9 +34,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" #include "cmsys/SystemInformation.hxx" -#if defined(_WIN32) -# include // IWYU pragma: keep -#else +#ifndef _WIN32 # include // IWYU pragma: keep #endif @@ -61,6 +59,7 @@ #include "cmState.h" #include "cmStateSnapshot.h" #include "cmStateTypes.h" +#include "cmStdIoStream.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmUVHandlePtr.h" @@ -1487,28 +1486,9 @@ bool cmCTest::CheckArgument(std::string const& arg, cm::string_view varg1, return (arg == varg1) || (varg2 && arg == varg2); } -#if !defined(_WIN32) -bool cmCTest::ConsoleIsNotDumb() -{ - std::string term_env_variable; - if (cmSystemTools::GetEnv("TERM", term_env_variable)) { - return isatty(1) && term_env_variable != "dumb"; - } - return false; -} -#endif - bool cmCTest::ProgressOutputSupportedByConsole() { -#if defined(_WIN32) - // On Windows we need a console buffer. - void* console = GetStdHandle(STD_OUTPUT_HANDLE); - CONSOLE_SCREEN_BUFFER_INFO csbi; - return GetConsoleScreenBufferInfo(console, &csbi); -#else - // On UNIX we need a non-dumb tty. - return ConsoleIsNotDumb(); -#endif + return cm::StdIo::Out().Kind() == cm::StdIo::TermKind::VT100; } bool cmCTest::ColoredOutputSupportedByConsole() @@ -1522,13 +1502,7 @@ bool cmCTest::ColoredOutputSupportedByConsole() if (cmSystemTools::GetEnv("CLICOLOR", clicolor) && clicolor == "0") { return false; } -#if defined(_WIN32) - // Not supported on Windows - return false; -#else - // On UNIX we need a non-dumb tty. - return ConsoleIsNotDumb(); -#endif + return cm::StdIo::Out().Kind() == cm::StdIo::TermKind::VT100; } bool cmCTest::AddVariableDefinition(std::string const& arg) diff --git a/Source/cmCTest.h b/Source/cmCTest.h index cc240ccde7..6dfa0bc1ad 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -455,11 +455,6 @@ private: /** set command line arguments read from a test preset */ bool SetArgsFromPreset(std::string const& presetName, bool listPresets); -#if !defined(_WIN32) - /** returns true iff the console supports progress output */ - static bool ConsoleIsNotDumb(); -#endif - /** returns true iff the console supports progress output */ static bool ProgressOutputSupportedByConsole();