summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-05-29 12:28:54 (GMT)
committerBrad King <brad.king@kitware.com>2024-05-29 12:28:54 (GMT)
commit713bca2677d6c0673d7a9ca012937486d4f1be1a (patch)
tree3c3c7af150a987021e0a5d5899767cd265bcb688
parent49c7a718de189c9553bb6accaedbe4e8afcfc74c (diff)
parent98dd754b624c2b60bd1a0817b3aa7784522f8d0a (diff)
downloadCMake-713bca2677d6c0673d7a9ca012937486d4f1be1a.zip
CMake-713bca2677d6c0673d7a9ca012937486d4f1be1a.tar.gz
CMake-713bca2677d6c0673d7a9ca012937486d4f1be1a.tar.bz2
Merge topic 'backport-kwsys-ConsoleBuf-windows-terminal' into release-3.28
98dd754b62 KWSys: ConsoleBuf: Fix test case when running under Windows Terminal 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(),