Skip to content

Commit dcd232a

Browse files
committed
Windows console updates
1 parent 883e220 commit dcd232a

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/hyperiond/console.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
#include <Windows.h>
22

3-
// https://stackoverflow.com/a/57241985
4-
void CreateConsole()
3+
void openConsole(bool isShowConsole)
54
{
6-
if (!AllocConsole()) {
7-
// Add some error handling here.
8-
// You can call GetLastError() to get more info about the error.
9-
return;
10-
}
11-
12-
// std::cout, std::clog, std::cerr, std::cin
13-
FILE* fDummy;
14-
freopen_s(&fDummy, "CONOUT$", "w", stdout);
15-
freopen_s(&fDummy, "CONOUT$", "w", stderr);
16-
freopen_s(&fDummy, "CONIN$", "r", stdin);
17-
SetConsoleTitle(TEXT("Hyperion"));
18-
SetConsoleOutputCP(CP_UTF8);
5+
if (AttachConsole(ATTACH_PARENT_PROCESS) || (isShowConsole && AllocConsole())) {
6+
FILE* fp;
7+
freopen_s(&fp, "CONOUT$", "w", stdout);
8+
freopen_s(&fp, "CONOUT$", "w", stderr);
9+
SetConsoleTitle(TEXT("Hyperion"));
10+
SetConsoleOutputCP(CP_UTF8);
11+
}
1912
}

src/hyperiond/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ int main(int argc, char** argv)
156156
parser.process(*qApp);
157157

158158
#ifdef WIN32
159-
if (parser.isSet(consoleOption))
160-
{
161-
CreateConsole();
162-
}
159+
bool isShowConsole = parser.isSet(consoleOption);
160+
openConsole(isShowConsole);
163161
#endif
164162

165163
if (parser.isSet(versionOption))

0 commit comments

Comments
 (0)