commit fe5bd8cdef2544ded69e0867d20bd3c9af3f949b
parent c848ec3d534f524f3a5c320d1dd739a11da7ed47
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 21 Sep 2019 19:23:52 +0200
usage: properly align --help output also when it has accented characters
As printf() is not UTF8-aware, we have to determine ourselves how many
columns each short and long flag take up and add the required number of
spaces (not tabs, because their size is not fixed) to fill things up.
This fixes https://savannah.gnu.org/bugs/?56928.
Bug existed since version 4.3, commit 2f169107.
Diffstat:
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -683,7 +683,18 @@ void mouse_init(void)
/* Print the usage line for the given option to the screen. */
void print_opt(const char *shortflag, const char *longflag, const char *desc)
{
- printf(" %-14s %-23s %s\n", shortflag, longflag, _(desc));
+ int firstwidth = breadth(shortflag);
+ int secondwidth = breadth(longflag);
+
+ printf(" %s", shortflag);
+ if (firstwidth < 14)
+ printf("%*s", 14 - firstwidth, " ");
+
+ printf(" %s", longflag);
+ if (secondwidth < 24)
+ printf("%*s", 24 - secondwidth, " ");
+
+ printf("%s\n", _(desc));
}
/* Explain how to properly use nano and its command-line options. */
@@ -696,7 +707,7 @@ void usage(void)
"a '+' before the filename. The column number can be added after a comma.\n"));
printf(_("When a filename is '-', nano reads data from standard input.\n\n"));
/* TRANSLATORS: The next three are column headers of the --help output. */
- printf("%-16s%-26s%s\n", _("Option"), _("Long option"), _("Meaning"));
+ print_opt(_("Option"), _("Long option"), N_("Meaning"));
#ifndef NANO_TINY
/* TRANSLATORS: The next forty or so strings are option descriptions
* for the --help output. Try to keep them at most 40 characters. */