diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index a49aac0f2..463e96146 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -114,7 +114,7 @@ macro(configurePackageCreation) set(application_type) set(imhex_icon "${CMAKE_SOURCE_DIR}/res/resource.rc") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wl,-subsystem,windows") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-subsystem,windows") if (CREATE_PACKAGE) set(CPACK_GENERATOR "WIX") diff --git a/source/window/win_window.cpp b/source/window/win_window.cpp index 781e7904b..f757018cf 100644 --- a/source/window/win_window.cpp +++ b/source/window/win_window.cpp @@ -170,15 +170,28 @@ void Window::initNative() { - auto hConsoleWindow = ::GetConsoleWindow(); - ::ShowWindow(hConsoleWindow, FALSE); + // Attach to parent console if one exists + AttachConsole(ATTACH_PARENT_PROCESS); - auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE); - if (hConsole != INVALID_HANDLE_VALUE) { - DWORD mode = 0; - if (::GetConsoleMode(hConsole, &mode)) { - mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; - ::SetConsoleMode(hConsole, mode); + // Redirect cin, cout and cerr to that console + freopen("CONIN$", "w", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONERR$", "w", stderr); + setvbuf(stdin, nullptr, _IONBF, 0); + setvbuf(stdout, nullptr, _IONBF, 0); + setvbuf(stderr, nullptr, _IONBF, 0); + + fmt::print("\n"); + + // Enable color format specifiers in console + { + auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE); + if (hConsole != INVALID_HANDLE_VALUE) { + DWORD mode = 0; + if (::GetConsoleMode(hConsole, &mode)) { + mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT; + ::SetConsoleMode(hConsole, mode); + } } } }