mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 11:44:18 +01:00
Global: support --*-key-color
This commit is contained in:
@@ -16,6 +16,11 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs*
|
||||
ffStrbufSetNS(&moduleArgs->key, (uint32_t) yyjson_get_len(val), yyjson_get_str(val));
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(key, "keyColor") == 0)
|
||||
{
|
||||
ffOptionParseColor(yyjson_get_str(val), &moduleArgs->keyColor);
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(key, "format") == 0)
|
||||
{
|
||||
ffStrbufSetNS(&moduleArgs->outputFormat, (uint32_t) yyjson_get_len(val), yyjson_get_str(val));
|
||||
|
||||
@@ -33,6 +33,16 @@ bool ffOptionParseModuleArgs(const char* argumentKey, const char* subKey, const
|
||||
ffOptionParseString(argumentKey, value, &result->key);
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(subKey, "key-color") == 0)
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error: usage: %s <str>\n", argumentKey);
|
||||
exit(477);
|
||||
}
|
||||
ffOptionParseColor(value, &result->keyColor);
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(subKey, "format") == 0)
|
||||
{
|
||||
ffOptionParseString(argumentKey, value, &result->outputFormat);
|
||||
@@ -132,11 +142,13 @@ void ffOptionParseColor(const char* value, FFstrbuf* buffer)
|
||||
void ffOptionInitModuleArg(FFModuleArgs* args)
|
||||
{
|
||||
ffStrbufInit(&args->key);
|
||||
ffStrbufInit(&args->keyColor);
|
||||
ffStrbufInit(&args->outputFormat);
|
||||
}
|
||||
|
||||
void ffOptionDestroyModuleArg(FFModuleArgs* args)
|
||||
{
|
||||
ffStrbufDestroy(&args->key);
|
||||
ffStrbufDestroy(&args->keyColor);
|
||||
ffStrbufDestroy(&args->outputFormat);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
typedef struct FFModuleArgs
|
||||
{
|
||||
FFstrbuf key;
|
||||
FFstrbuf keyColor;
|
||||
FFstrbuf outputFormat;
|
||||
} FFModuleArgs;
|
||||
|
||||
|
||||
+13
-10
@@ -2,7 +2,7 @@
|
||||
#include "common/printing.h"
|
||||
#include "util/textModifier.h"
|
||||
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat)
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor)
|
||||
{
|
||||
ffLogoPrintLine(instance);
|
||||
|
||||
@@ -13,7 +13,10 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
|
||||
if(!instance->config.pipe)
|
||||
{
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_RESET FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
|
||||
ffPrintColor(&instance->config.colorKeys);
|
||||
if(customKeyColor != NULL && customKeyColor->length > 0)
|
||||
ffPrintColor(customKeyColor);
|
||||
else
|
||||
ffPrintColor(&instance->config.colorKeys);
|
||||
}
|
||||
|
||||
//NULL check is required for modules with custom keys, e.g. disk with the folder path
|
||||
@@ -42,14 +45,14 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
|
||||
}
|
||||
|
||||
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments)
|
||||
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateA(256);
|
||||
ffParseFormatString(&buffer, format, numArgs, arguments);
|
||||
|
||||
if(buffer.length > 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
|
||||
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat, customKeyColor);
|
||||
ffPrintUserString(buffer.chars);
|
||||
putchar('\n');
|
||||
}
|
||||
@@ -57,15 +60,15 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m
|
||||
|
||||
void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments)
|
||||
{
|
||||
ffPrintFormatString(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->outputFormat, numArgs, arguments);
|
||||
ffPrintFormatString(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->keyColor, &moduleArgs->outputFormat, numArgs, arguments);
|
||||
}
|
||||
|
||||
static void printError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const char* message, va_list arguments)
|
||||
static void printError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const char* message, va_list arguments)
|
||||
{
|
||||
if(!instance->config.showErrors)
|
||||
return;
|
||||
|
||||
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
|
||||
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat, customKeyColor);
|
||||
|
||||
if(!instance->config.pipe)
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout);
|
||||
@@ -78,11 +81,11 @@ static void printError(FFinstance* instance, const char* moduleName, uint8_t mod
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const char* message, ...)
|
||||
void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const char* message, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
va_start(arguments, message);
|
||||
printError(instance, moduleName, moduleIndex, customKeyFormat, message, arguments);
|
||||
printError(instance, moduleName, moduleIndex, customKeyFormat, customKeyColor, message, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
@@ -90,7 +93,7 @@ void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIn
|
||||
{
|
||||
va_list arguments;
|
||||
va_start(arguments, message);
|
||||
printError(instance, moduleName, moduleIndex, &moduleArgs->key, message, arguments);
|
||||
printError(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->keyColor, message, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/format.h"
|
||||
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat);
|
||||
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments);
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor);
|
||||
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments);
|
||||
void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments);
|
||||
FF_C_PRINTF(5, 6) void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const char* message, ...);
|
||||
FF_C_PRINTF(6, 7) void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const char* message, ...);
|
||||
FF_C_PRINTF(5, 6) void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...);
|
||||
void ffPrintColor(const FFstrbuf* colorValue);
|
||||
void ffPrintCharTimes(char c, uint32_t times);
|
||||
|
||||
Reference in New Issue
Block a user