Rework stdout buffering on Windows.

Windows doesn't support line-buffering. We enable full-buffering instead and flush buffers per module.
This commit is contained in:
李通洲
2022-12-14 16:27:04 +08:00
parent d151901049
commit e4a5194115
7 changed files with 22 additions and 19 deletions
+6
View File
@@ -354,6 +354,9 @@ void ffStart(FFinstance* instance)
ffHideCursor = instance->config.hideCursor && !instance->config.pipe;
#ifdef _WIN32
#ifdef FF_ENABLE_BUFFER
setvbuf(stdout, NULL, _IOFBF, 4096);
#endif
SetConsoleCtrlHandler(consoleHandler, TRUE);
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD mode = 0;
@@ -361,6 +364,9 @@ void ffStart(FFinstance* instance)
SetConsoleMode(hStdout, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
SetConsoleOutputCP(CP_UTF8);
#else
#ifndef FF_ENABLE_BUFFER
setvbuf(stdout, NULL, _IONBF, 0);
#endif
struct sigaction action = { .sa_handler = exitSignalHandler };
sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, NULL);
-6
View File
@@ -40,12 +40,6 @@
# Default is false.
#--stat true
# Disable stdout buffer option:
# Sets if fastfetch should disable application buffer of stdout. Mainly for debugging purpose.
# Must be true or false.
# Default is false.
#--unbuffered false
# Slow operations option:
# Sets if fastfetch is allowed to use known slow operations to detect more / better values.
# Must be true or false.
-1
View File
@@ -20,7 +20,6 @@ General options:
--multithreading <?value>: use multiple threads to detect values
--stat <?value>: print time usage (in ms) for individual modules
--allow-slow-operations <?value>: allow operations that are usually very slow for more detailed output
--unbuffered <?value>: disable stdout application buffer
--escape-bedrock <?value>: on bedrock linux, sets if it should escape the bedrock jail or not
--pipe <?value>: disable logo and all escape sequences
+4 -5
View File
@@ -916,11 +916,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
}
else if(strcasecmp(key, "--allow-slow-operations") == 0)
instance->config.allowSlowOperations = optionParseBoolean(value);
else if(strcasecmp(key, "--unbuffered") == 0)
{
if(optionParseBoolean(value))
setvbuf(stdout, NULL, _IONBF, 0);
}
else if(strcasecmp(key, "--escape-bedrock") == 0)
instance->config.escapeBedrock = optionParseBoolean(value);
else if(strcasecmp(key, "--pipe") == 0)
@@ -1435,6 +1430,10 @@ int main(int argc, const char** argv)
printf("\033[s\033[1A\033[9999999C\033[%dD%s\033[u", len, str); // Save; Up 1; Right 9999999; Left <len>; Print <str>; Load
}
#if defined(_WIN32) && defined(FF_ENABLE_BUFFER)
fflush(stdout);
#endif
startIndex = colonIndex + 1;
}