From 05121eebd1f219e9ae1cdf79afa8d0201ad7975a Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Tue, 10 Jul 2018 10:36:36 +0200 Subject: [PATCH] isoltest: adds support for properly handling ANSI escape sequences on Win32/Win64 builds. --- test/tools/isoltest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 41dff148e..ed4f148ee 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -29,6 +29,10 @@ #include #include +#if defined(_WIN32) +#include +#endif + using namespace dev; using namespace dev::solidity; using namespace dev::solidity::test; @@ -242,8 +246,30 @@ TestStats TestTool::processPath( } +void setupTerminal() +{ +#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING) + // Set output mode to handle virtual terminal (ANSI escape sequences) + // ignore any error, as this is just a "nice-to-have" + // only windows needs to be taken care of, as other platforms (Linux/OSX) support them natively. + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (hOut == INVALID_HANDLE_VALUE) + return; + + DWORD dwMode = 0; + if (!GetConsoleMode(hOut, &dwMode)) + return; + + dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + if (!SetConsoleMode(hOut, dwMode)) + return; +#endif +} + int main(int argc, char *argv[]) { + setupTerminal(); + if (getenv("EDITOR")) TestTool::editor = getenv("EDITOR"); else if (fs::exists("/usr/bin/editor"))