From 043c41dfc70a7f67928bc2b4b5e34c3b03df8933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 13 Jun 2023 11:08:49 +0800 Subject: [PATCH] Fastfetch: add `--no-buffer` option --- .github/workflows/push.yml | 12 ++++++------ CHANGELOG.md | 1 + CMakeLists.txt | 10 ---------- src/common/init.c | 11 ++++------- src/common/jsonconfig.c | 6 ++++-- src/data/config_user.txt | 6 ++++++ src/data/help.txt | 3 ++- src/fastfetch.c | 10 ++++++---- src/fastfetch.h | 1 + 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 3a50a9026..9c46ce25a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -39,7 +39,7 @@ jobs: run: ctest - name: run fastfetch - run: ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: ./fastfetch --disable-linewrap false --hide-cursor false --show-errors --no-buffer --load-config presets/all - name: run flashfetch run: ./flashfetch @@ -77,7 +77,7 @@ jobs: run: ./fastfetch --list-features - name: run fastfetch - run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors --no-buffer --load-config presets/all - name: run flashfetch run: time ./flashfetch @@ -126,7 +126,7 @@ jobs: run: ./fastfetch --list-features - name: run fastfetch - run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors --no-buffer --load-config presets/all - name: run flashfetch run: time ./flashfetch @@ -159,7 +159,7 @@ jobs: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . cmake --build . --target package ./fastfetch --list-features - time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors --no-buffer --load-config presets/all time ./flashfetch ctest @@ -213,7 +213,7 @@ jobs: run: ./fastfetch --list-features - name: run fastfetch - run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors --no-buffer --load-config presets/all - name: run flashfetch run: time ./flashfetch @@ -271,7 +271,7 @@ jobs: run: cp /clang32/bin/{OpenCL,vulkan-1}.dll . - name: run fastfetch - run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors --no-buffer --load-config presets/all - name: run flashfetch run: time ./flashfetch diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b481c75..5d8835339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Features: * Support KDE / LXQT / MATE / Cinnamon wallpaper detection (Wallpaper, Linux) * Support QTerminal version & terminal font detection * Support MATE Terminal version & terminal font detection +* Add `--no-buffer` option for easier debugging. CMake option `ENABLE_BUFFER` is removed and always enabled. # 1.11.3 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c735c21d..c711b8b7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,6 @@ cmake_dependent_option(ENABLE_LIBNM "Enable libnm" ON "LINUX" OFF) cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF) cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) -cmake_dependent_option(ENABLE_BUFFER "Enable stdout buffer" ON "LINUX OR APPLE OR BSD OR WIN32 OR ANDROID" OFF) option(BUILD_TESTS "Build tests" OFF) # Also create test executables option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds @@ -715,10 +714,6 @@ if(ENABLE_THREADS) endif() endif() -if(ENABLE_BUFFER) - target_compile_definitions(libfastfetch PRIVATE FF_ENABLE_BUFFER) -endif() - if(APPLE) target_link_libraries(libfastfetch PRIVATE "-framework Cocoa" @@ -791,11 +786,6 @@ target_link_libraries(flashfetch PRIVATE yyjson ) -if(ENABLE_BUFFER) # FF_ENABLE_BUFFER is used in fastfetch.c - target_compile_definitions(fastfetch PRIVATE FF_ENABLE_BUFFER) - target_compile_definitions(flashfetch PRIVATE FF_ENABLE_BUFFER) -endif() - if(WIN32) set(TARGET_NAME fastfetch) target_sources(fastfetch diff --git a/src/common/init.c b/src/common/init.c index c8bb50f91..281bbbdf4 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -51,6 +51,7 @@ static void defaultConfig(FFinstance* instance) instance->config.pipe = false; instance->config.multithreading = true; instance->config.stat = false; + instance->config.noBuffer = false; ffInitTitleOptions(&instance->config.title); ffInitOSOptions(&instance->config.os); @@ -175,7 +176,7 @@ static void resetConsole() if(ffHideCursor) fputs("\033[?25h", stdout); - #if defined(_WIN32) && defined(FF_ENABLE_BUFFER) + #if defined(_WIN32) fflush(stdout); #endif } @@ -207,9 +208,7 @@ void ffStart(FFinstance* instance) ffHideCursor = instance->config.hideCursor && !instance->config.pipe; #ifdef _WIN32 - #ifdef FF_ENABLE_BUFFER - setvbuf(stdout, NULL, _IOFBF, 4096); - #endif + if (!instance->config.noBuffer) setvbuf(stdout, NULL, _IOFBF, 4096); SetConsoleCtrlHandler(consoleHandler, TRUE); HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); DWORD mode = 0; @@ -217,9 +216,7 @@ 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 + if (instance->config.noBuffer) setvbuf(stdout, NULL, _IONBF, 0); struct sigaction action = { .sa_handler = exitSignalHandler }; sigaction(SIGINT, &action, NULL); sigaction(SIGTERM, &action, NULL); diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index f4e0ff4e9..0b41fd2da 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -266,8 +266,8 @@ static const char* printJsonConfig(FFinstance* instance) printf("\033[s\033[1A\033[9999999C\033[%dD%s\033[u", len, str); // Save; Up 1; Right 9999999; Left ; Print ; Load } - #if defined(_WIN32) && defined(FF_ENABLE_BUFFER) - fflush(stdout); + #if defined(_WIN32) + if (!instance->config.noBuffer) fflush(stdout); #endif } @@ -380,6 +380,8 @@ const char* ffParseDisplayJsonConfig(FFinstance* instance) } else if (strcasecmp(key, "percentType") == 0) config->percentType = (uint32_t) yyjson_get_uint(val); + else if (strcasecmp(key, "noBuffer") == 0) + config->noBuffer = yyjson_get_bool(val); else return "Unknown display property"; } diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 58b55653a..0c91e60e6 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -146,6 +146,12 @@ # Default is IEC. #--binary-prefix IEC +# Disable output buffer option: +# Sets if the stdout application buffer should be disabled. +# Must be true or false. +# Default is false. +#--no-buffer false + # Title FQDN option: # Sets if the title should use the fully qualified domain name. # Must be true or false. diff --git a/src/data/help.txt b/src/data/help.txt index 8c96ab9c0..462f55ac1 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -62,7 +62,8 @@ Display options: --show-errors : Print occurring errors --disable-linewrap : Whether to disable line wrap during the run --hide-cursor : Whether to hide the cursor during the run - --binary-prefix : Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC. + --binary-prefix : Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC + --no-buffer : Set if the stdout application buffer should be disabled. Default is false General module options: ---format : Set the format string to use for each specific module. diff --git a/src/fastfetch.c b/src/fastfetch.c index 47b5ebdf9..cea9b37c1 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -884,6 +884,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con } else if(strcasecmp(key, "--percent-type") == 0) instance->config.percentType = ffOptionParseUInt32(key, value); + else if(strcasecmp(key, "--no-buffer") == 0) + instance->config.noBuffer = ffOptionParseBoolean(value); /////////////////////// //Module args options// @@ -1201,8 +1203,8 @@ int main(int argc, const char** argv) ffStart(&instance); - #if defined(_WIN32) && defined(FF_ENABLE_BUFFER) - fflush(stdout); + #if defined(_WIN32) + if (!instance.config.noBuffer) fflush(stdout); #endif if (instance.state.configDoc) @@ -1234,8 +1236,8 @@ 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 ; Print ; Load } - #if defined(_WIN32) && defined(FF_ENABLE_BUFFER) - fflush(stdout); + #if defined(_WIN32) + if (!instance.config.noBuffer) fflush(stdout); #endif startIndex = colonIndex + 1; diff --git a/src/fastfetch.h b/src/fastfetch.h index a5e859ecc..0ecbcd12a 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -47,6 +47,7 @@ typedef struct FFconfig bool pipe; //disables logo and all escape sequences bool multithreading; bool stat; + bool noBuffer; // Module options that cannot be put in module option structure #if defined(__linux__) || defined(__FreeBSD__)