Skip to contentSkip to conversation

help: align the longest command in the command listing

PATCH In review Nguyễn Thái Ngọc Duy 2 participants 3 messages Jan 31, 2019 – Feb 1, 2019

lore
Share & tools
lore
#0 lore raw

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
index ff05fd22df..520c9080e8 100644
@@ -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
#1 lore raw

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 ...

---
 help.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
help.c +0 -0
index ff05fd22df..520c9080e8 100644

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 -0
 			puts(_(cmds[i].help));
 		}
 	}
Signature · 1 line
2.20.1.682.gd5861c6d90
author
#2 lore raw
Quoted 5 lines · Johannes Schindelin
Quoted 5 lines
help.c +0 -0
index ff05fd22df..520c9080e8 100644
@@ -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 -1
              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?

While it makes the diff shorter, I think it's a bit more confusing (why add zero spaces?)

Signature · 1 line
Duy