From 5172a13b15524fc94bfb54508109f766664a3935 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 28 May 2024 15:37:00 +0800 Subject: [PATCH] Global: fix `outputColor` doesn't work if module keys are disabled --- src/common/printing.c | 78 +++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/common/printing.c b/src/common/printing.c index 080db6be..90b2ad7a 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -11,43 +11,50 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu return; //This is used as a magic value for hiding keys - if(moduleArgs && ffStrbufEqualS(&moduleArgs->key, " ")) - return; - - if(!instance.config.display.pipe) + if (!(moduleArgs && ffStrbufEqualS(&moduleArgs->key, " "))) { - fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); - if (instance.config.display.brightColor) - fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout); + if(!instance.config.display.pipe) + { + fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); + if (instance.config.display.brightColor) + fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout); - if(moduleArgs && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR) && moduleArgs->keyColor.length > 0) - ffPrintColor(&moduleArgs->keyColor); + if(moduleArgs && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR) && moduleArgs->keyColor.length > 0) + ffPrintColor(&moduleArgs->keyColor); + else + ffPrintColor(&instance.config.display.colorKeys); + } + + //NULL check is required for modules with custom keys, e.g. disk with the folder path + if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0) + { + fputs(moduleName, stdout); + + if(moduleIndex > 0) + printf(" %hhu", moduleIndex); + } else - ffPrintColor(&instance.config.display.colorKeys); + { + FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); + FF_PARSE_FORMAT_STRING_CHECKED(&key, &moduleArgs->key, 1, ((FFformatarg[]){ + {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex, "index"}, + })); + ffStrbufWriteTo(&key, stdout); + } + + if(!instance.config.display.pipe) + fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); + + ffStrbufWriteTo(&instance.config.display.keyValueSeparator, stdout); + + if (!(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH)) + { + uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.display.keyWidth; + if (keyWidth > 0) + printf("\e[%uG", (unsigned) (keyWidth + instance.state.logoWidth)); + } } - //NULL check is required for modules with custom keys, e.g. disk with the folder path - if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0) - { - fputs(moduleName, stdout); - - if(moduleIndex > 0) - printf(" %hhu", moduleIndex); - } - else - { - FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); - FF_PARSE_FORMAT_STRING_CHECKED(&key, &moduleArgs->key, 1, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex, "index"}, - })); - ffStrbufWriteTo(&key, stdout); - } - - if(!instance.config.display.pipe) - fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); - - ffStrbufWriteTo(&instance.config.display.keyValueSeparator, stdout); - if(!instance.config.display.pipe) { fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); @@ -56,13 +63,6 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu else if (instance.config.display.colorOutput.length) ffPrintColor(&instance.config.display.colorOutput); } - - if (!(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH)) - { - uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.display.keyWidth; - if (keyWidth > 0) - printf("\e[%uG", (unsigned) (keyWidth + instance.state.logoWidth)); - } } void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments)