Skip to content

Commit 32dcf94

Browse files
committed
Option: adds configurable spacing between icon and string keys
Fixes #2004
1 parent e3a698f commit 32dcf94

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

doc/json_schema.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,9 +1024,30 @@
10241024
},
10251025
{
10261026
"const": "both",
1027-
"description": "Show both icon and string keys"
1027+
"description": "Show both icon and string keys (alias of `both-1`)"
1028+
},
1029+
{
1030+
"const": "both-0",
1031+
"description": "Show both icon and string with no spaces between them"
1032+
},
1033+
{
1034+
"const": "both-1",
1035+
"description": "Show both icon and string with a space between them"
1036+
},
1037+
{
1038+
"const": "both-2",
1039+
"description": "Show both icon and string with 2 spaces between them"
1040+
},
1041+
{
1042+
"const": "both-3",
1043+
"description": "Show both icon and string with 3 spaces between them"
1044+
},
1045+
{
1046+
"const": "both-4",
1047+
"description": "Show both icon and string with 4 spaces between them"
10281048
}
10291049
],
1050+
],
10301051
"default": "string"
10311052
},
10321053
"paddingLeft": {

src/common/option.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ typedef enum __attribute__((__packed__)) FFModuleKeyType
4444
FF_MODULE_KEY_TYPE_NONE = 0,
4545
FF_MODULE_KEY_TYPE_STRING = 1 << 0,
4646
FF_MODULE_KEY_TYPE_ICON = 1 << 1,
47-
FF_MODULE_KEY_TYPE_BOTH = FF_MODULE_KEY_TYPE_STRING | FF_MODULE_KEY_TYPE_ICON,
47+
FF_MODULE_KEY_TYPE_SPACE_SHIFT = 4,
48+
FF_MODULE_KEY_TYPE_BOTH_0 = FF_MODULE_KEY_TYPE_STRING | FF_MODULE_KEY_TYPE_ICON,
49+
FF_MODULE_KEY_TYPE_BOTH_1 = FF_MODULE_KEY_TYPE_BOTH_0 | (1 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
50+
FF_MODULE_KEY_TYPE_BOTH = FF_MODULE_KEY_TYPE_BOTH_1, // alias
51+
FF_MODULE_KEY_TYPE_BOTH_2 = FF_MODULE_KEY_TYPE_BOTH_0 | (2 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
52+
FF_MODULE_KEY_TYPE_BOTH_3 = FF_MODULE_KEY_TYPE_BOTH_0 | (3 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
53+
FF_MODULE_KEY_TYPE_BOTH_4 = FF_MODULE_KEY_TYPE_BOTH_0 | (4 << FF_MODULE_KEY_TYPE_SPACE_SHIFT),
4854
FF_MODULE_KEY_TYPE_FORCE_UNSIGNED = UINT8_MAX,
4955
} FFModuleKeyType;
5056

src/common/printing.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,12 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu
2828
ffPrintColor(&instance.config.display.colorKeys);
2929
}
3030

31-
bool hasIcon = false;
3231
if (instance.config.display.keyType & FF_MODULE_KEY_TYPE_ICON && moduleArgs && moduleArgs->keyIcon.length > 0)
33-
{
3432
ffStrbufWriteTo(&moduleArgs->keyIcon, stdout);
35-
hasIcon = true;
36-
}
3733

3834
if (instance.config.display.keyType & FF_MODULE_KEY_TYPE_STRING)
3935
{
40-
if(hasIcon)
41-
putchar(' ');
36+
ffPrintCharTimes(' ', instance.config.display.keyType >> FF_MODULE_KEY_TYPE_SPACE_SHIFT);
4237

4338
//NULL check is required for modules with custom keys, e.g. disk with the folder path
4439
if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0)
@@ -136,6 +131,12 @@ void ffPrintCharTimes(char c, uint32_t times)
136131
if(times == 0)
137132
return;
138133

134+
if(times == 1)
135+
{
136+
putchar(c);
137+
return;
138+
}
139+
139140
char str[32];
140141
memset(str, c, sizeof(str)); //2 instructions when compiling with AVX2 enabled
141142
for(uint32_t i = sizeof(str); i <= times; i += (uint32_t)sizeof(str))

src/data/help.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,12 @@
566566
"none": "Disable keys",
567567
"string": "Show string",
568568
"icon": "Show icon (requires newest nerd font)",
569-
"both": "Show both icon and string"
569+
"both": "Show both icon and string (alias of `both-1`)",
570+
"both-0": "Show both icon and string with no spaces between them",
571+
"both-1": "Show both icon and string with a space between them",
572+
"both-2": "Show both icon and string with 2 spaces between them",
573+
"both-3": "Show both icon and string with 3 spaces between them",
574+
"both-4": "Show both icon and string with 4 spaces between them"
570575
},
571576
"default": "string"
572577
}

src/options/display.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
451451
{ "string", FF_MODULE_KEY_TYPE_STRING },
452452
{ "icon", FF_MODULE_KEY_TYPE_ICON },
453453
{ "both", FF_MODULE_KEY_TYPE_BOTH },
454+
{ "both-0", FF_MODULE_KEY_TYPE_BOTH_0 },
455+
{ "both-1", FF_MODULE_KEY_TYPE_BOTH_1 },
456+
{ "both-2", FF_MODULE_KEY_TYPE_BOTH_2 },
457+
{ "both-3", FF_MODULE_KEY_TYPE_BOTH_3 },
458+
{ "both-4", FF_MODULE_KEY_TYPE_BOTH_4 },
454459
{}
455460
});
456461
if (error) return error;
@@ -612,6 +617,11 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
612617
{ "string", FF_MODULE_KEY_TYPE_STRING },
613618
{ "icon", FF_MODULE_KEY_TYPE_ICON },
614619
{ "both", FF_MODULE_KEY_TYPE_BOTH },
620+
{ "both-0", FF_MODULE_KEY_TYPE_BOTH_0 },
621+
{ "both-1", FF_MODULE_KEY_TYPE_BOTH_1 },
622+
{ "both-2", FF_MODULE_KEY_TYPE_BOTH_2 },
623+
{ "both-3", FF_MODULE_KEY_TYPE_BOTH_3 },
624+
{ "both-4", FF_MODULE_KEY_TYPE_BOTH_4 },
615625
{}
616626
});
617627
}

0 commit comments

Comments
 (0)