fix: Log was not being output to the console if one was open
This commit is contained in:
parent
243820ca95
commit
efad16f2c0
@ -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")
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user