Option: adds configurable spacing between icon and string keys

Fixes #2004
This commit is contained in:
李通洲
2025-10-13 09:54:34 +08:00
parent e3a698f7b1
commit 32dcf9487f
5 changed files with 52 additions and 9 deletions
+22 -1
View File
@@ -1024,9 +1024,30 @@
},
{
"const": "both",
"description": "Show both icon and string keys"
"description": "Show both icon and string keys (alias of `both-1`)"
},
{
"const": "both-0",
"description": "Show both icon and string with no spaces between them"
},
{
"const": "both-1",
"description": "Show both icon and string with a space between them"
},
{
"const": "both-2",
"description": "Show both icon and string with 2 spaces between them"
},
{
"const": "both-3",
"description": "Show both icon and string with 3 spaces between them"
},
{
"const": "both-4",
"description": "Show both icon and string with 4 spaces between them"
}
],
],
"default": "string"
},
"paddingLeft": {
+7 -1
View File
@@ -44,7 +44,13 @@ typedef enum __attribute__((__packed__)) FFModuleKeyType
FF_MODULE_KEY_TYPE_NONE = 0,
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,
FF_MODULE_KEY_TYPE_SPACE_SHIFT = 4,
FF_MODULE_KEY_TYPE_BOTH_0 = FF_MODULE_KEY_TYPE_STRING | FF_MODULE_KEY_TYPE_ICON,
FF_MODULE_KEY_TYPE_BOTH_1 = FF_MODULE_KEY_TYPE_BOTH_0 | (1 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
FF_MODULE_KEY_TYPE_BOTH = FF_MODULE_KEY_TYPE_BOTH_1, // alias
FF_MODULE_KEY_TYPE_BOTH_2 = FF_MODULE_KEY_TYPE_BOTH_0 | (2 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
FF_MODULE_KEY_TYPE_BOTH_3 = FF_MODULE_KEY_TYPE_BOTH_0 | (3 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
FF_MODULE_KEY_TYPE_BOTH_4 = FF_MODULE_KEY_TYPE_BOTH_0 | (4 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
FF_MODULE_KEY_TYPE_FORCE_UNSIGNED = UINT8_MAX,
} FFModuleKeyType;
+7 -6
View File
@@ -28,17 +28,12 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu
ffPrintColor(&instance.config.display.colorKeys);
}
bool hasIcon = false;
if (instance.config.display.keyType & FF_MODULE_KEY_TYPE_ICON && moduleArgs && moduleArgs->keyIcon.length > 0)
{
ffStrbufWriteTo(&moduleArgs->keyIcon, stdout);
hasIcon = true;
}
if (instance.config.display.keyType & FF_MODULE_KEY_TYPE_STRING)
{
if(hasIcon)
putchar(' ');
ffPrintCharTimes(' ', instance.config.display.keyType >> FF_MODULE_KEY_TYPE_SPACE_SHIFT);
//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)
@@ -136,6 +131,12 @@ void ffPrintCharTimes(char c, uint32_t times)
if(times == 0)
return;
if(times == 1)
{
putchar(c);
return;
}
char str[32];
memset(str, c, sizeof(str)); //2 instructions when compiling with AVX2 enabled
for(uint32_t i = sizeof(str); i <= times; i += (uint32_t)sizeof(str))
+6 -1
View File
@@ -566,7 +566,12 @@
"none": "Disable keys",
"string": "Show string",
"icon": "Show icon (requires newest nerd font)",
"both": "Show both icon and string"
"both": "Show both icon and string (alias of `both-1`)",
"both-0": "Show both icon and string with no spaces between them",
"both-1": "Show both icon and string with a space between them",
"both-2": "Show both icon and string with 2 spaces between them",
"both-3": "Show both icon and string with 3 spaces between them",
"both-4": "Show both icon and string with 4 spaces between them"
},
"default": "string"
}
+10
View File
@@ -451,6 +451,11 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
{ "string", FF_MODULE_KEY_TYPE_STRING },
{ "icon", FF_MODULE_KEY_TYPE_ICON },
{ "both", FF_MODULE_KEY_TYPE_BOTH },
{ "both-0", FF_MODULE_KEY_TYPE_BOTH_0 },
{ "both-1", FF_MODULE_KEY_TYPE_BOTH_1 },
{ "both-2", FF_MODULE_KEY_TYPE_BOTH_2 },
{ "both-3", FF_MODULE_KEY_TYPE_BOTH_3 },
{ "both-4", FF_MODULE_KEY_TYPE_BOTH_4 },
{}
});
if (error) return error;
@@ -612,6 +617,11 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
{ "string", FF_MODULE_KEY_TYPE_STRING },
{ "icon", FF_MODULE_KEY_TYPE_ICON },
{ "both", FF_MODULE_KEY_TYPE_BOTH },
{ "both-0", FF_MODULE_KEY_TYPE_BOTH_0 },
{ "both-1", FF_MODULE_KEY_TYPE_BOTH_1 },
{ "both-2", FF_MODULE_KEY_TYPE_BOTH_2 },
{ "both-3", FF_MODULE_KEY_TYPE_BOTH_3 },
{ "both-4", FF_MODULE_KEY_TYPE_BOTH_4 },
{}
});
}