From: Kir Kolyshkin <kolyshkin@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Torsten Bögershausen" <tboegi@web.de>,
"Kir Kolyshkin" <kolyshkin@gmail.com>,
"Roman Dodin" <dodin.roman@gmail.com>
Subject: [PATCH] remote: align columns on -v
Date: Wed, 8 Feb 2023 17:12:01 -0800 [thread overview]
Message-ID: <20230209011201.1974721-1-kolyshkin@gmail.com> (raw)
In-Reply-To: <20230207235238.1850757-1-kolyshkin@gmail.com>
Currently, git remote -v produces a misaligned output when some remote
names are shorter and some are longer than a tab step. For example:
giuseppe https://github.com/giuseppe/runc (fetch)
giuseppe https://github.com/giuseppe/runc (push)
kir git@github.com:kolyshkin/runc.git (fetch)
kir git@github.com:kolyshkin/runc.git (push)
lifubang https://github.com/lifubang/runc (fetch)
lifubang https://github.com/lifubang/runc (push)
marquiz https://github.com/marquiz/runc (fetch)
marquiz https://github.com/marquiz/runc (push)
Let's find the maximum width of remote and use it for alignment.
With this change in place, the output looks like this now:
giuseppe https://github.com/giuseppe/runc (fetch)
giuseppe https://github.com/giuseppe/runc (push)
kir git@github.com:kolyshkin/runc.git (fetch)
kir git@github.com:kolyshkin/runc.git (push)
lifubang https://github.com/lifubang/runc (fetch)
lifubang https://github.com/lifubang/runc (push)
marquiz https://github.com/marquiz/runc (fetch)
marquiz https://github.com/marquiz/runc (push)
[v2: use utf8_strwidth and padding, fix description]
Reported-by: Roman Dodin <dodin.roman@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
---
builtin/remote.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 729f6f3643..654472a87c 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -13,6 +13,7 @@
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
+#include "utf8.h"
static const char * const builtin_remote_usage[] = {
"git remote [-v | --verbose]",
@@ -1245,14 +1246,26 @@ static int show_all(void)
result = for_each_remote(get_one_entry, &list);
if (!result) {
- int i;
+ int i, width = 7;
+
+ if (verbose) {
+ for (i = 0; i < list.nr; i++) {
+ int w = utf8_strwidth((list.items + i)->string);
+ if (w > width)
+ width = w;
+ }
+ }
string_list_sort(&list);
for (i = 0; i < list.nr; i++) {
struct string_list_item *item = list.items + i;
- if (verbose)
- printf("%s\t%s\n", item->string,
+ if (verbose) {
+ int padding = width - utf8_strwidth(item->string);
+ if (padding < 0)
+ padding = 0;
+ printf("%*s%s %s\n", padding, "", item->string,
item->util ? (const char *)item->util : "");
+ }
else {
if (i && !strcmp((item - 1)->string, item->string))
continue;
--
2.39.0
prev parent reply other threads:[~2023-02-09 1:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 23:52 [PATCH] remote: align columns on -v Kir Kolyshkin
2023-02-08 16:12 ` Torsten Bögershausen
2023-02-08 16:32 ` Junio C Hamano
2023-02-09 1:02 ` Kirill Kolyshkin
2023-02-08 16:19 ` Junio C Hamano
2023-02-09 1:11 ` Kirill Kolyshkin
2023-02-09 1:12 ` Kir Kolyshkin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230209011201.1974721-1-kolyshkin@gmail.com \
--to=kolyshkin@gmail.com \
--cc=dodin.roman@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=tboegi@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).