summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-05-29 12:29:46 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-05-29 12:30:11 (GMT)
commit631934633d36d8ad567c2fc3510a16e3158eef6e (patch)
treee1197476be0b8c43e7c776632762c3f79140086a
parentd636cd2ba96c916b5200e385525a7ac0088bc981 (diff)
parentb2081e3810b9e7f1cbd0920aa9a1f1e8549b1136 (diff)
downloadCMake-631934633d36d8ad567c2fc3510a16e3158eef6e.zip
CMake-631934633d36d8ad567c2fc3510a16e3158eef6e.tar.gz
CMake-631934633d36d8ad567c2fc3510a16e3158eef6e.tar.bz2
Merge topic 'update-kwsys'
b2081e3810 Merge branch 'backport-kwsys-ConsoleBuf-windows-terminal' into update-kwsys 98dd754b62 KWSys: ConsoleBuf: Fix test case when running under Windows Terminal a151fdda01 Merge branch 'upstream-KWSys' into update-kwsys c6ef3299d0 KWSys 2024-05-28 (0d6eac1f) Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9553
-rw-r--r--Source/kwsys/testConsoleBuf.cxx26
1 files changed, 25 insertions, 1 deletions
diff --git a/Source/kwsys/testConsoleBuf.cxx b/Source/kwsys/testConsoleBuf.cxx
index f9b826d..64c61e2 100644
--- a/Source/kwsys/testConsoleBuf.cxx
+++ b/Source/kwsys/testConsoleBuf.cxx
@@ -476,6 +476,22 @@ static int testFile()
# define _WIN32_WINNT_VISTA 0x0600
# endif
+static bool consoleIsConhost()
+{
+ wchar_t consoleClassNameBuf[64];
+ int const consoleClassNameLen = GetClassNameW(
+ GetConsoleWindow(), &consoleClassNameBuf[0], sizeof(consoleClassNameBuf));
+ // Windows Console Host: ConsoleWindowClass
+ // Windows Terminal / ConPTY: PseudoConsoleWindow (undocumented)
+ return (consoleClassNameLen > 0 &&
+ wcscmp(consoleClassNameBuf, L"ConsoleWindowClass") == 0);
+}
+
+static bool charIsNUL(wchar_t c)
+{
+ return c == 0;
+}
+
static int testConsole()
{
int didFail = 1;
@@ -691,7 +707,15 @@ static int testConsole()
throw std::runtime_error("ReadConsoleOutputCharacter failed!");
}
std::wstring wideTestString = kwsys::Encoding::ToWide(encodedTestString);
- std::replace(wideTestString.begin(), wideTestString.end(), '\0', ' ');
+ if (consoleIsConhost()) {
+ // Windows Console Host converts NUL bytes to spaces.
+ std::replace(wideTestString.begin(), wideTestString.end(), '\0', ' ');
+ } else {
+ // Windows Terminal / ConPTY removes NUL bytes.
+ wideTestString.erase(std::remove_if(wideTestString.begin(),
+ wideTestString.end(), charIsNUL),
+ wideTestString.end());
+ }
std::wstring wideInputTestString =
kwsys::Encoding::ToWide(encodedInputTestString);
if (memcmp(outputBuffer, wideTestString.c_str(),