diff --git a/CHANGELOG.md b/CHANGELOG.md index 89cfb0b40..b1098eb19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 2.0.1 + +Changes: +* Unescape strings only when parsing `.conf` files + * Previously: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\: *`. Note the backslashs are unescaped twice (once by shell and once by fastfetch). + * Now: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\\: *` + # 2.0.0 (beta) Fastfetch v2 introduces a new configuration file format: JSON config. Please refer to for details. diff --git a/src/common/printing.c b/src/common/printing.c index 1ef1a0ea6..35ab27aa0 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -36,7 +36,7 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex} }); - ffPrintUserString(key.chars); + ffStrbufWriteTo(&key, stdout); } if(!instance.config.pipe) @@ -56,8 +56,7 @@ void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFst if(buffer.length > 0) { ffPrintLogoAndKey(moduleName, moduleIndex, customKeyFormat, customKeyColor); - ffPrintUserString(buffer.chars); - putchar('\n'); + ffStrbufPutTo(&buffer, stdout); } } @@ -125,34 +124,3 @@ void ffPrintCharTimes(char c, uint32_t times) if(remaining > 0) fwrite(str, 1, remaining, stdout); } - -void ffPrintUserString(const char* value) -{ - while(*value != '\0') - { - if(*value != '\\') - { - putchar(*value); - ++value; - continue; - } - - ++value; - - if(*value == 'n') - putchar('\n'); - else if(*value == 't') - putchar('\t'); - else if(*value == 'e') - putchar('\e'); - else if(*value == '\\') - putchar('\\'); - else - { - putchar('\\'); - putchar(*value); - } - - ++value; - } -} diff --git a/src/common/printing.h b/src/common/printing.h index 8019a01cc..e25c0f82c 100644 --- a/src/common/printing.h +++ b/src/common/printing.h @@ -13,6 +13,5 @@ FF_C_PRINTF(5, 6) void ffPrintErrorString(const char* moduleName, uint8_t module FF_C_PRINTF(4, 5) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...); void ffPrintColor(const FFstrbuf* colorValue); void ffPrintCharTimes(char c, uint32_t times); -void ffPrintUserString(const char* str); #endif diff --git a/src/fastfetch.c b/src/fastfetch.c index e0e32f9d7..00d3d43ff 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -584,6 +584,7 @@ static bool parseConfigFile(FFdata* data, const char* path) char* line = NULL; size_t len = 0; ssize_t read; + FF_STRBUF_AUTO_DESTROY unescaped = ffStrbufCreate(); while ((read = getline(&line, &len, file)) != -1) { @@ -628,7 +629,42 @@ static bool parseConfigFile(FFdata* data, const char* path) --lineEnd; } - parseOption(data, lineStart, valueStart); + if (strchr(valueStart, '\\')) + { + // Unescape all `\x`s + const char* value = valueStart; + while(*value != '\0') + { + if(*value != '\\') + { + ffStrbufAppendC(&unescaped, *value); + ++value; + continue; + } + + ++value; + + switch(*value) + { + case 'n': ffStrbufAppendC(&unescaped, '\n'); break; + case 't': ffStrbufAppendC(&unescaped, '\t'); break; + case 'e': ffStrbufAppendC(&unescaped, '\e'); break; + case '\\': ffStrbufAppendC(&unescaped, '\\'); break; + default: + ffStrbufAppendC(&unescaped, '\\'); + ffStrbufAppendC(&unescaped, *value); + break; + } + + ++value; + } + parseOption(data, lineStart, unescaped.chars); + ffStrbufClear(&unescaped); + } + else + { + parseOption(data, lineStart, valueStart); + } } if(line != NULL) diff --git a/src/modules/custom/custom.c b/src/modules/custom/custom.c index 64ab00579..105823651 100644 --- a/src/modules/custom/custom.c +++ b/src/modules/custom/custom.c @@ -13,7 +13,7 @@ void ffPrintCustom(FFCustomOptions* options) } ffPrintLogoAndKey(options->moduleArgs.key.length == 0 ? NULL : FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); - ffPrintUserString(options->moduleArgs.outputFormat.chars); + ffStrbufWriteTo(&options->moduleArgs.outputFormat, stdout); puts(FASTFETCH_TEXT_MODIFIER_RESET); }