print_category: print help descriptions aligned

Adjust the description position to make an aligned column when doing
help listings, which is more pleasing to the eye.

Suggested-by: Gisle Vanem
Closes #7792
This commit is contained in:
Daniel Stenberg 2021-09-29 12:43:09 +02:00
parent 85f91248cf
commit 24ffdc8826
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 36 additions and 19 deletions

View file

@ -115,9 +115,26 @@ static const struct feat feats[] = {
static void print_category(curlhelp_t category)
{
unsigned int i;
size_t longopt = 5;
size_t longdesc = 5;
for(i = 0; helptext[i].opt; ++i) {
size_t len;
if(!(helptext[i].categories & category))
continue;
len = strlen(helptext[i].opt);
if(len > longopt)
longopt = len;
len = strlen(helptext[i].desc);
if(len > longdesc)
longdesc = len;
}
if(longopt + longdesc > 80)
longopt = 80 - longdesc;
for(i = 0; helptext[i].opt; ++i)
if(helptext[i].categories & category) {
printf(" %-18s %s\n", helptext[i].opt, helptext[i].desc);
printf(" %-*s %s\n", longopt, helptext[i].opt, helptext[i].desc);
}
}