Skip to content

Commit 14cd933

Browse files
lildannitaCarterLi
authored andcommitted
fix(help): align format placeholders dynamically
1 parent 6550b77 commit 14cd933

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/fastfetch.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ static void printCommandFormatHelp(const char* command) {
6262
puts("To see how a format string is constructed, take a look at https://github.com/fastfetch-cli/fastfetch/wiki/Format-String-Guide.");
6363
puts("The following variables are passed:");
6464

65+
uint32_t maxWidth = 20;
66+
for (unsigned i = 0; i < baseInfo->formatArgs.count; i++) {
67+
uint32_t len = (uint32_t) strlen(baseInfo->formatArgs.args[i].name) + 2;
68+
if (len > maxWidth) {
69+
maxWidth = len;
70+
}
71+
}
72+
6573
for (unsigned i = 0; i < baseInfo->formatArgs.count; i++) {
6674
const FFModuleFormatArg* arg = &baseInfo->formatArgs.args[i];
6775
ffStrbufSetF(&variable, "{%s}", arg->name);
68-
printf("%20s: %s\n", variable.chars, arg->desc);
76+
printf("%*s: %s\n", (int) maxWidth, variable.chars, arg->desc);
6977
}
7078
} else {
7179
fprintf(stderr, "Error: Module '%s' doesn't support output formatting\n", baseInfo->name);

0 commit comments

Comments
 (0)