mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Fastfetch: add option --key-type <enum>
This commit is contained in:
parent
640d0666fc
commit
8fa4d7ae6e
@ -424,6 +424,17 @@
|
||||
"minimum": 0,
|
||||
"default": 0
|
||||
},
|
||||
"keyType": {
|
||||
"type": "string",
|
||||
"description": "Set the type of keys to display",
|
||||
"enum": [
|
||||
"none",
|
||||
"string",
|
||||
"icon",
|
||||
"botn"
|
||||
],
|
||||
"default": "string"
|
||||
},
|
||||
"size": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
|
@ -48,9 +48,9 @@ static inline void ffOptionInitModuleBaseInfo(
|
||||
typedef enum FFModuleKeyType
|
||||
{
|
||||
FF_MODULE_KEY_TYPE_NONE = 0,
|
||||
FF_MODULE_KEY_TYPE_STRING = 0 << 1,
|
||||
FF_MODULE_KEY_TYPE_KEY = 1 << 1,
|
||||
FF_MODULE_KEY_TYPE_BOTH = FF_MODULE_KEY_TYPE_STRING | FF_MODULE_KEY_TYPE_KEY,
|
||||
FF_MODULE_KEY_TYPE_STRING = 1 << 0,
|
||||
FF_MODULE_KEY_TYPE_ICON = 1 << 1,
|
||||
FF_MODULE_KEY_TYPE_BOTH = FF_MODULE_KEY_TYPE_STRING | FF_MODULE_KEY_TYPE_ICON,
|
||||
} FFModuleKeyType;
|
||||
|
||||
typedef struct FFModuleArgs
|
||||
|
@ -11,7 +11,7 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu
|
||||
return;
|
||||
|
||||
//This is used as a magic value for hiding keys
|
||||
if (!(moduleArgs && ffStrbufEqualS(&moduleArgs->key, " ")))
|
||||
if (!(moduleArgs && ffStrbufEqualS(&moduleArgs->key, " ")) && instance.config.display.keyType != FF_MODULE_KEY_TYPE_NONE)
|
||||
{
|
||||
if(!instance.config.display.pipe)
|
||||
{
|
||||
@ -25,22 +25,35 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu
|
||||
ffPrintColor(&instance.config.display.colorKeys);
|
||||
}
|
||||
|
||||
//NULL check is required for modules with custom keys, e.g. disk with the folder path
|
||||
if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0)
|
||||
bool hasIcon = false;
|
||||
if (instance.config.display.keyType & FF_MODULE_KEY_TYPE_ICON && moduleArgs && moduleArgs->icon.length > 0)
|
||||
{
|
||||
fputs(moduleName, stdout);
|
||||
|
||||
if(moduleIndex > 0)
|
||||
printf(" %hhu", moduleIndex);
|
||||
ffStrbufWriteTo(&moduleArgs->icon, stdout);
|
||||
hasIcon = true;
|
||||
}
|
||||
else
|
||||
|
||||
if (instance.config.display.keyType & FF_MODULE_KEY_TYPE_STRING)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
FF_PARSE_FORMAT_STRING_CHECKED(&key, &moduleArgs->key, 2, ((FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex, "index"},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &moduleArgs->icon, "icon"},
|
||||
}));
|
||||
ffStrbufWriteTo(&key, stdout);
|
||||
if(hasIcon)
|
||||
putchar(' ');
|
||||
|
||||
//NULL check is required for modules with custom keys, e.g. disk with the folder path
|
||||
if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0)
|
||||
{
|
||||
fputs(moduleName, stdout);
|
||||
|
||||
if(moduleIndex > 0)
|
||||
printf(" %hhu", moduleIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
FF_PARSE_FORMAT_STRING_CHECKED(&key, &moduleArgs->key, 2, ((FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex, "index"},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &moduleArgs->icon, "icon"},
|
||||
}));
|
||||
ffStrbufWriteTo(&key, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
if(!instance.config.display.pipe)
|
||||
|
@ -505,6 +505,20 @@
|
||||
"type": "num"
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "key-type",
|
||||
"desc": "Set the type of keys to display",
|
||||
"arg": {
|
||||
"type": "enum",
|
||||
"enum": {
|
||||
"none": "Disable keys",
|
||||
"string": "Show string",
|
||||
"icon": "Show icon",
|
||||
"both": "Show both icon and string"
|
||||
},
|
||||
"default": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "bright-color",
|
||||
"desc": "Set if the keys, title and ASCII logo should be printed in bright color",
|
||||
|
@ -203,6 +203,19 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
|
||||
options->noBuffer = yyjson_get_bool(val);
|
||||
else if (ffStrEqualsIgnCase(key, "keyWidth"))
|
||||
options->keyWidth = (uint32_t) yyjson_get_uint(val);
|
||||
else if (ffStrEqualsIgnCase(key, "keyType"))
|
||||
{
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "none", FF_MODULE_KEY_TYPE_NONE },
|
||||
{ "string", FF_MODULE_KEY_TYPE_STRING },
|
||||
{ "icon", FF_MODULE_KEY_TYPE_ICON },
|
||||
{ "both", FF_MODULE_KEY_TYPE_BOTH },
|
||||
{}
|
||||
});
|
||||
if (error) return error;
|
||||
options->keyType = (uint8_t) value;
|
||||
}
|
||||
else if (ffStrEqualsIgnCase(key, "constants"))
|
||||
{
|
||||
if (!yyjson_is_arr(val))
|
||||
@ -288,6 +301,16 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--key-width"))
|
||||
options->keyWidth = ffOptionParseUInt32(key, value);
|
||||
else if(ffStrEqualsIgnCase(key, "--key-type"))
|
||||
{
|
||||
options->keyType = (FFModuleKeyType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "none", FF_MODULE_KEY_TYPE_NONE },
|
||||
{ "string", FF_MODULE_KEY_TYPE_STRING },
|
||||
{ "icon", FF_MODULE_KEY_TYPE_ICON },
|
||||
{ "both", FF_MODULE_KEY_TYPE_BOTH },
|
||||
{}
|
||||
});
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--bright-color"))
|
||||
options->brightColor = ffOptionParseBoolean(value);
|
||||
else if(ffStrEqualsIgnCase(key, "--binary-prefix"))
|
||||
@ -425,6 +448,7 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options)
|
||||
options->stat = false;
|
||||
options->noBuffer = false;
|
||||
options->keyWidth = 0;
|
||||
options->keyType = FF_MODULE_KEY_TYPE_STRING;
|
||||
|
||||
options->tempUnit = FF_TEMPERATURE_UNIT_CELSIUS;
|
||||
options->tempNdigits = 1;
|
||||
@ -623,6 +647,9 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do
|
||||
if (options->keyWidth != defaultOptions.keyWidth)
|
||||
yyjson_mut_obj_add_uint(doc, obj, "keyWidth", options->keyWidth);
|
||||
|
||||
if (options->keyType != defaultOptions.keyType)
|
||||
yyjson_mut_obj_add_uint(doc, obj, "keyType", options->keyType);
|
||||
|
||||
{
|
||||
yyjson_mut_val* freq = yyjson_mut_obj(doc);
|
||||
if (options->freqNdigits != defaultOptions.freqNdigits)
|
||||
|
@ -53,6 +53,7 @@ typedef struct FFOptionsDisplay
|
||||
FFstrbuf percentColorRed;
|
||||
bool noBuffer;
|
||||
uint32_t keyWidth;
|
||||
FFModuleKeyType keyType;
|
||||
int8_t freqNdigits;
|
||||
FFlist constants; // list of FFstrbuf
|
||||
} FFOptionsDisplay;
|
||||
|
Loading…
x
Reference in New Issue
Block a user