git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] help: align the longest command in the command listing
@ 2019-01-31  9:23 Nguyễn Thái Ngọc Duy
  2019-02-01  7:42 ` Johannes Schindelin
  0 siblings, 1 reply; 3+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-01-31  9:23 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, 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 <pclouds@gmail.com>
---
 help.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/help.c b/help.c
index ff05fd22df..520c9080e8 100644
--- a/help.c
+++ b/help.c
@@ -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));
 		}
 	}
-- 
2.20.1.682.gd5861c6d90


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] help: align the longest command in the command listing
  2019-01-31  9:23 [PATCH] help: align the longest command in the command listing Nguyễn Thái Ngọc Duy
@ 2019-02-01  7:42 ` Johannes Schindelin
  2019-02-01  8:24   ` Duy Nguyen
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2019-02-01  7:42 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]

Hi Duy,

On Thu, 31 Jan 2019, Nguyễn Thái Ngọc Duy wrote:

> "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 <pclouds@gmail.com>
> ---
>  help.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/help.c b/help.c
> index ff05fd22df..520c9080e8 100644
> --- a/help.c
> +++ b/help.c
> @@ -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

>  			puts(_(cmds[i].help));
>  		}
>  	}
> -- 
> 2.20.1.682.gd5861c6d90
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] help: align the longest command in the command listing
  2019-02-01  7:42 ` Johannes Schindelin
@ 2019-02-01  8:24   ` Duy Nguyen
  0 siblings, 0 replies; 3+ messages in thread
From: Duy Nguyen @ 2019-02-01  8:24 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Git Mailing List, Junio C Hamano

On Fri, Feb 1, 2019 at 2:42 PM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> > diff --git a/help.c b/help.c
> > index ff05fd22df..520c9080e8 100644
> > --- a/help.c
> > +++ b/help.c
> > @@ -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`?

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-01  8:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-31  9:23 [PATCH] help: align the longest command in the command listing Nguyễn Thái Ngọc Duy
2019-02-01  7:42 ` Johannes Schindelin
2019-02-01  8:24   ` Duy Nguyen

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).