mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Fastfetch: unescape strings only when parsing .conf files
So that `NO_CONFIG=1 ./fastfetch --os-key \\\\ -s os -l none` prints `\\: *`
This commit is contained in:
@@ -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 <https://github.com/fastfetch-cli/fastfetch/wiki/Configuration> for details.
|
||||
|
||||
+2
-34
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+37
-1
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user