--set-keyless option

This commit is contained in:
Linus Dierheimer
2022-08-18 10:44:21 +02:00
parent f9562d7132
commit 83016289e9
4 changed files with 42 additions and 22 deletions
+1
View File
@@ -156,6 +156,7 @@ __fastfetch_completion()
"-s"
"--structure"
"--set"
"--set-keyless"
"--gl"
"--os-format"
"--os-key"
+4
View File
@@ -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);
+1
View File
@@ -43,6 +43,7 @@ Display options:
-c,--color <color>: sets the color of the keys. Must be a linux console color code or the name of a color (+)
--separator <str>: sets the separator between key and value. Default is a colon with a space
--set <key=value>: hard set the value of a key
--set-keyless <key=value>: hard set the value of a key, but don't print the key or the separator
--show-errors <?value>: print occuring errors
--disable-linewrap <?value>: weather to disable linewrap during the run
--hide-cursor <?value>: weather to hide the cursor during the run
+36 -22
View File
@@ -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 <key=value>\n", key);
exit(411);
}
char* separator = strchr(value, '=');
if(separator == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>, '=' 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 <key=value>\n", key);
exit(411);
}
char* separator = strchr(value, '=');
if(separator == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>, '=' 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;