cmdline-opts: shorter help texts

In an effort to increase the readability of the "--help all" output on
narrow (80 column) terminals.

Co-authored-by: Jay Satiro

Closes #13169
This commit is contained in:
Daniel Stenberg 2024-03-25 10:02:30 +01:00
parent 647e86a3ef
commit fe9f68fa61
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
70 changed files with 215 additions and 170 deletions

View file

@ -73,6 +73,11 @@ static const struct category_descriptors categories[] = {
{NULL, NULL, CURLHELP_HIDDEN}
};
#ifdef _WIN32
#define BORDER 78
#else
#define BORDER 79
#endif
static void print_category(curlhelp_t category)
{
@ -91,12 +96,21 @@ static void print_category(curlhelp_t category)
if(len > longdesc)
longdesc = len;
}
if(longopt + longdesc > 80)
longopt = 80 - longdesc;
if(longopt + longdesc >= BORDER) {
longdesc -= 3;
longopt = BORDER -1 - longdesc;
}
for(i = 0; helptext[i].opt; ++i)
if(helptext[i].categories & category) {
printf(" %-*s %s\n", (int)longopt, helptext[i].opt, helptext[i].desc);
int opt = (int)longopt;
size_t desclen = strlen(helptext[i].desc);
if(opt + desclen >= (BORDER -1)) {
if(desclen < (BORDER -1))
opt = (BORDER -2) - (int)desclen;
else
opt = 0;
}
printf(" %-*s %s\n", opt, helptext[i].opt, helptext[i].desc);
}
}