# [PATCH] help: align the longest command in the command listing

3 messages from 2019-01-31 to 2019-02-01. Participants: Nguyễn Thái Ngọc Duy, Johannes Schindelin, Duy Nguyen.
Thread: https://gitlist.dev/t/50369

## Nguyễn Thái Ngọc Duy, 2019-01-31 09:23

Subject: [PATCH] help: align the longest command in the command listing
Message-ID: <20190131092349.11469-1-pclouds@gmail.com>
URL: https://gitlist.dev/e/20190131092349.11469-1-pclouds%40gmail.com

```
"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


```

## Johannes Schindelin, 2019-02-01 07:42

Subject: Re: [PATCH] help: align the longest command in the command listing
Message-ID: <nycvar.QRO.7.76.6.1902010842010.41@tvgsbejvaqbjf.bet>
URL: https://gitlist.dev/e/nycvar.QRO.7.76.6.1902010842010.41%40tvgsbejvaqbjf.bet
In-Reply-To: <20190131092349.11469-1-pclouds@gmail.com>

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

## Duy Nguyen, 2019-02-01 08:24

Subject: Re: [PATCH] help: align the longest command in the command listing
Message-ID: <CACsJy8B=7NsnnoSH1Bt_C-Nop95ky=rudHU3SOVERVudDD7Tfw@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8B%3D7NsnnoSH1Bt_C-Nop95ky%3DrudHU3SOVERVudDD7Tfw%40mail.gmail.com
In-Reply-To: <nycvar.QRO.7.76.6.1902010842010.41@tvgsbejvaqbjf.bet>

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

```
