help: align the longest command in the command listing
PATCH 1/1 help: align the longest command in the command listing
"longest" is used to determine how many extra spaces we need to print to keep the command description aligned. For the longest command, we should print no extra space instead of one, or we'll get unaligned output like this (notice the "checkout" line):
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and ...
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag ...
--- help.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
help.c +2 -1
@@ -85,7 +85,8 @@ static void print_command_list(const struct cmdname_help *cmds,if (cmds[i].category & mask) {size_t len =strlen (cmds[i].name);printf (" %s " , cmds[i].name); -mput_char (' ' , longest > len ? longest - len :1 ); +if (longest > len) +mput_char (' ' , longest - len);puts (_ (cmds[i].help)); } }
Signature · 1 line
2.20.1.682.gd5861c6d90
Hi Duy,
Quoted 24 lines · Nguyễn Thái Ngọc Duy
"longest" is used to determine how many extra spaces we need to print to keep the command description aligned. For the longest command, we should print no extra space instead of one, or we'll get unaligned output like this (notice the "checkout" line):
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and ...
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag ...Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- help.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)help.c +0
-0
help.c static void print_command_list(const struct cmdname_help *cmds, · line 89
Quoted 6 lines
help.c +2
-1@@ -85,7 +85,8 @@ static void print_command_list(const struct cmdname_help *cmds,if (cmds[i].category & mask) {size_t len =strlen (cmds[i].name);printf (" %s " , cmds[i].name); -mput_char (' ' , longest > len ? longest - len :1 ); +if (longest > len) +mput_char (' ' , longest - len);
Why not simply replace the 1 by 0?
Ciao,
Dscho
Quoted 7 lines
help.c +0
-0puts (_ (cmds[i].help)); } }Signature · 1 line
2.20.1.682.gd5861c6d90
Quoted 5 lines · Johannes Schindelin
Quoted 5 lines
help.c +0
-0@@ -85,7 +85,8 @@ static void print_command_list(const struct cmdname_help *cmds,
Quoted 8 lines
help.c static void print_command_list(const struct cmdname_help *cmds, · line 89
Quoted 6 lines
help.c +2
-1if (cmds[i].category & mask) {size_t len =strlen (cmds[i].name);printf (" %s " , cmds[i].name); -mput_char (' ' , longest > len ? longest - len :1 ); +if (longest > len) +mput_char (' ' , longest - len);Why not simply replace the
1by0?
While it makes the diff shorter, I think it's a bit more confusing (why add zero spaces?)
Signature · 1 line
Duy