Skip to content

Commit a5306d6

Browse files
committed
Windows: enable console processing, disable output buffer
UCRT doesn't support line buffering, which makes modules being not printed ASAP
1 parent e3de39d commit a5306d6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/common/init.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ static void initState(FFstate* state)
125125
#ifdef WIN32
126126
//https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?source=recommendations&view=msvc-170#utf-8-support
127127
setlocale(LC_ALL, ".UTF8");
128-
setvbuf(stdout, NULL, _IOFBF, 4096);
129128
#endif
130129

131130
state->logoWidth = 0;
@@ -334,12 +333,9 @@ static void resetConsole()
334333
#ifdef _WIN32
335334
BOOL WINAPI consoleHandler(DWORD signal)
336335
{
337-
if(signal == CTRL_C_EVENT)
338-
{
339-
resetConsole();
340-
return TRUE;
341-
}
342-
return false;
336+
FF_UNUSED(signal);
337+
resetConsole();
338+
exit(0);
343339
}
344340
#else
345341
static void exitSignalHandler(int signal)
@@ -360,6 +356,11 @@ void ffStart(FFinstance* instance)
360356

361357
#ifdef _WIN32
362358
SetConsoleCtrlHandler(consoleHandler, TRUE);
359+
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
360+
DWORD mode = 0;
361+
GetConsoleMode(hStdout, &mode);
362+
SetConsoleMode(hStdout, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
363+
SetConsoleOutputCP(CP_UTF8);
363364
#else
364365
struct sigaction action = { .sa_handler = exitSignalHandler };
365366
sigaction(SIGINT, &action, NULL);

0 commit comments

Comments
 (0)