Fastfetch: add option --key-type <enum>

This commit is contained in:
李通洲
2024-07-24 11:13:37 +08:00
parent 640d0666fc
commit 8fa4d7ae6e
6 changed files with 83 additions and 17 deletions
+3 -3
View File
@@ -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
+27 -14
View File
@@ -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)