diff --git a/src/FGJSBBase.cpp b/src/FGJSBBase.cpp index 43f98f0d9..ac0f6b36e 100644 --- a/src/FGJSBBase.cpp +++ b/src/FGJSBBase.cpp @@ -46,31 +46,17 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#ifndef _MSC_VER - char FGJSBBase::highint[5] = {27, '[', '1', 'm', '\0' }; - char FGJSBBase::halfint[5] = {27, '[', '2', 'm', '\0' }; - char FGJSBBase::normint[6] = {27, '[', '2', '2', 'm', '\0' }; - char FGJSBBase::reset[5] = {27, '[', '0', 'm', '\0' }; - char FGJSBBase::underon[5] = {27, '[', '4', 'm', '\0' }; - char FGJSBBase::underoff[6] = {27, '[', '2', '4', 'm', '\0' }; - char FGJSBBase::fgblue[6] = {27, '[', '3', '4', 'm', '\0' }; - char FGJSBBase::fgcyan[6] = {27, '[', '3', '6', 'm', '\0' }; - char FGJSBBase::fgred[6] = {27, '[', '3', '1', 'm', '\0' }; - char FGJSBBase::fggreen[6] = {27, '[', '3', '2', 'm', '\0' }; - char FGJSBBase::fgdef[6] = {27, '[', '3', '9', 'm', '\0' }; -#else - char FGJSBBase::highint[5] = {'\0' }; - char FGJSBBase::halfint[5] = {'\0' }; - char FGJSBBase::normint[6] = {'\0' }; - char FGJSBBase::reset[5] = {'\0' }; - char FGJSBBase::underon[5] = {'\0' }; - char FGJSBBase::underoff[6] = {'\0' }; - char FGJSBBase::fgblue[6] = {'\0' }; - char FGJSBBase::fgcyan[6] = {'\0' }; - char FGJSBBase::fgred[6] = {'\0' }; - char FGJSBBase::fggreen[6] = {'\0' }; - char FGJSBBase::fgdef[6] = {'\0' }; -#endif +char FGJSBBase::highint[5] = {27, '[', '1', 'm', '\0' }; +char FGJSBBase::halfint[5] = {27, '[', '2', 'm', '\0' }; +char FGJSBBase::normint[6] = {27, '[', '2', '2', 'm', '\0' }; +char FGJSBBase::reset[5] = {27, '[', '0', 'm', '\0' }; +char FGJSBBase::underon[5] = {27, '[', '4', 'm', '\0' }; +char FGJSBBase::underoff[6] = {27, '[', '2', '4', 'm', '\0' }; +char FGJSBBase::fgblue[6] = {27, '[', '3', '4', 'm', '\0' }; +char FGJSBBase::fgcyan[6] = {27, '[', '3', '6', 'm', '\0' }; +char FGJSBBase::fgred[6] = {27, '[', '3', '1', 'm', '\0' }; +char FGJSBBase::fggreen[6] = {27, '[', '3', '2', 'm', '\0' }; +char FGJSBBase::fgdef[6] = {27, '[', '3', '9', 'm', '\0' }; const string FGJSBBase::needed_cfg_version = "2.0"; const string FGJSBBase::JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__ ; diff --git a/src/JSBSim.cpp b/src/JSBSim.cpp index 18226301b..c4d3f69fe 100644 --- a/src/JSBSim.cpp +++ b/src/JSBSim.cpp @@ -68,6 +68,11 @@ INCLUDES # include #endif +// The flag ENABLE_VIRTUAL_TERMINAL_PROCESSING is not defined for MinGW < 7.0.0 +#if defined(__MINGW64_VERSION_MAJOR) && __MINGW64_VERSION_MAJOR < 7 +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4 +#endif + #include #include @@ -360,6 +365,17 @@ int real_main(int argc, char* argv[]) FDMExec->GetPropertyManager()->Tie("simulation/frame_start_time", &actual_elapsed_time); FDMExec->GetPropertyManager()->Tie("simulation/cycle_duration", &cycle_duration); + // Check whether to disable console highlighting output on Windows. + // Support was added to Windows for Virtual Terminal codes by a particular + // Windows 10 release. +#ifdef _WIN32 + HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD dwMode = 0; + GetConsoleMode(hStdOut, &dwMode); + if ((dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0) + nohighlight = true; +#endif + if (nohighlight) FDMExec->disableHighLighting(); if (simulation_rate < 1.0 ) diff --git a/tests/unit_tests/FGLogTest.h b/tests/unit_tests/FGLogTest.h index 1c82e44f7..aac8dffc1 100644 --- a/tests/unit_tests/FGLogTest.h +++ b/tests/unit_tests/FGLogTest.h @@ -318,11 +318,7 @@ void testRedFormat() { log << JSBSim::LogFormat::RESET; } std::cout.rdbuf(cout_buffer); -#ifdef _MSC_VER - TS_ASSERT_EQUALS(buffer.str(), "Hello, World!"); -#else TS_ASSERT_EQUALS(buffer.str(), "\033[31mHello, World!\033[0m"); -#endif } void testCyanFormat() { @@ -337,11 +333,7 @@ void testCyanFormat() { log << JSBSim::LogFormat::RESET; } std::cout.rdbuf(cout_buffer); -#ifdef _MSC_VER - TS_ASSERT_EQUALS(buffer.str(), "Hello, World!"); -#else TS_ASSERT_EQUALS(buffer.str(), "\033[34mHello, World!\033[0m"); -#endif } void testBoldFormat() { @@ -356,11 +348,7 @@ void testBoldFormat() { log << JSBSim::LogFormat::RESET; } std::cout.rdbuf(cout_buffer); -#ifdef _MSC_VER - TS_ASSERT_EQUALS(buffer.str(), "Hello, World!"); -#else TS_ASSERT_EQUALS(buffer.str(), "\033[1mHello, World!\033[0m"); -#endif } void testNormalFormat() { @@ -375,11 +363,7 @@ void testNormalFormat() { log << JSBSim::LogFormat::RESET; } std::cout.rdbuf(cout_buffer); -#ifdef _MSC_VER - TS_ASSERT_EQUALS(buffer.str(), "Hello, World!"); -#else TS_ASSERT_EQUALS(buffer.str(), "\033[22mHello, World!\033[0m"); -#endif } void testUnderlineFormat() { @@ -394,11 +378,7 @@ void testUnderlineFormat() { log << JSBSim::LogFormat::UNDERLINE_OFF; } std::cout.rdbuf(cout_buffer); -#ifdef _MSC_VER - TS_ASSERT_EQUALS(buffer.str(), "Hello, World!"); -#else TS_ASSERT_EQUALS(buffer.str(), "\033[4mHello, World!\033[24m"); -#endif } void testDefaultFormat() { @@ -413,10 +393,6 @@ void testDefaultFormat() { log << JSBSim::LogFormat::RESET; } std::cout.rdbuf(cout_buffer); -#ifdef _MSC_VER - TS_ASSERT_EQUALS(buffer.str(), "Hello, World!"); -#else TS_ASSERT_EQUALS(buffer.str(), "\033[39mHello, World!\033[0m"); -#endif } };