From 83016289e9271f1c5f2e33e90a90faac514d9968 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 18 Aug 2022 10:44:21 +0200 Subject: [PATCH] --set-keyless option --- completions/bash | 1 + src/common/printing.c | 4 +++ src/data/help.txt | 1 + src/fastfetch.c | 58 +++++++++++++++++++++++++++---------------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/completions/bash b/completions/bash index ca18eeb67..c5aa99ee9 100644 --- a/completions/bash +++ b/completions/bash @@ -156,6 +156,7 @@ __fastfetch_completion() "-s" "--structure" "--set" + "--set-keyless" "--gl" "--os-format" "--os-key" diff --git a/src/common/printing.c b/src/common/printing.c index 44acf4f65..7ce26e93b 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -5,6 +5,10 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod { ffLogoPrintLine(instance); + //This is used by --set-keyless, in this case we wan't neither the module name nor the separator + if(moduleName == NULL) + return; + if(!instance->config.pipe) { fputs(FASTFETCH_TEXT_MODIFIER_RESET FASTFETCH_TEXT_MODIFIER_BOLT, stdout); diff --git a/src/data/help.txt b/src/data/help.txt index ec4aafbc2..dfa64861b 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -43,6 +43,7 @@ Display options: -c,--color : sets the color of the keys. Must be a linux console color code or the name of a color (+) --separator : sets the separator between key and value. Default is a colon with a space --set : hard set the value of a key + --set-keyless : hard set the value of a key, but don't print the key or the separator --show-errors : print occuring errors --disable-linewrap : weather to disable linewrap during the run --hide-cursor : weather to hide the cursor during the run diff --git a/src/fastfetch.c b/src/fastfetch.c index 211fe3a70..aa32dd3aa 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -11,7 +11,8 @@ // Things only needed by fastfetch typedef struct FFdata { - FFvaluestore valuestore; + FFvaluestore customWithKey; //Prints with key + FFvaluestore customKeyless; //Prints without FFstrbuf structure; bool loadUserConfig; } FFdata; @@ -668,6 +669,27 @@ static uint32_t optionParseUInt32(const char* key, const char* value) return num; } +static void optionParseCustom(const char* key, const char* value, FFvaluestore* valuestore) +{ + if(value == NULL) + { + fprintf(stderr, "Error: usage: %s \n", key); + exit(411); + } + + char* separator = strchr(value, '='); + + if(separator == NULL) + { + fprintf(stderr, "Error: usage: %s , '=' missing\n", key); + exit(412); + } + + *separator = '\0'; + + ffValuestoreSet(valuestore, value, separator + 1); +} + static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value) { /////////////////////// @@ -879,25 +901,9 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0) optionParseColor(key, value, &instance->config.mainColor); else if(strcasecmp(key, "--set") == 0) - { - if(value == NULL) - { - fprintf(stderr, "Error: usage: %s \n", key); - exit(411); - } - - char* separator = strchr(value, '='); - - if(separator == NULL) - { - fprintf(stderr, "Error: usage: %s , '=' missing\n", key); - exit(412); - } - - *separator = '\0'; - - ffValuestoreSet(&data->valuestore, value, separator + 1); - } + optionParseCustom(key, value, &data->customWithKey); + else if(strcasecmp(key, "--set-keyless") == 0) + optionParseCustom(key, value, &data->customKeyless); //////////////////////////////// //Format + Key + Error options// @@ -1279,13 +1285,20 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c static void parseStructureCommand(FFinstance* instance, FFdata* data, const char* line) { - const char* setValue = ffValuestoreGet(&data->valuestore, line); + const char* setValue = ffValuestoreGet(&data->customWithKey, line); if(setValue != NULL) { ffPrintCustom(instance, line, setValue); return; } + setValue = ffValuestoreGet(&data->customKeyless, line); + if(setValue != NULL) + { + ffPrintCustom(instance, NULL, setValue); + return; + } + if(strcasecmp(line, "break") == 0) ffPrintBreak(instance); else if(strcasecmp(line, "title") == 0) @@ -1373,7 +1386,8 @@ int main(int argc, const char** argv) //Data stores things only needed for the configuration of fastfetch FFdata data; - ffValuestoreInit(&data.valuestore); + ffValuestoreInit(&data.customWithKey); + ffValuestoreInit(&data.customKeyless); ffStrbufInitA(&data.structure, 256); data.loadUserConfig = true;