From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH v2 2/4] wt-status: extract the code to compute width for labels
Date: Wed, 12 Mar 2014 14:19:32 -0700 [thread overview]
Message-ID: <1394659174-9143-3-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1394659174-9143-1-git-send-email-gitster@pobox.com>
From: Jonathan Nieder <jrnieder@gmail.com>
From: Jonathan Nieder <jrnieder@gmail.com>
Date: Thu, 19 Dec 2013 11:43:19 -0800
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
wt-status.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 9cf7028..db98c52 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -292,6 +292,19 @@ static const char *wt_status_diff_status_string(int status)
}
}
+static int maxwidth(const char *(*label)(int), int minval, int maxval)
+{
+ int result = 0, i;
+
+ for (i = minval; i <= maxval; i++) {
+ const char *s = label(i);
+ int len = s ? utf8_strwidth(s) : 0;
+ if (len > result)
+ result = len;
+ }
+ return result;
+}
+
static void wt_status_print_change_data(struct wt_status *s,
int change_type,
struct string_list_item *it)
@@ -310,13 +323,8 @@ static void wt_status_print_change_data(struct wt_status *s,
int len;
if (!padding) {
- /* If DIFF_STATUS_* uses outside this range, we're in trouble */
- for (status = 'A'; status <= 'Z'; status++) {
- what = wt_status_diff_status_string(status);
- len = what ? strlen(what) : 0;
- if (len > label_width)
- label_width = len;
- }
+ /* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */
+ label_width = maxwidth(wt_status_diff_status_string, 'A', 'Z');
label_width += strlen(" ");
padding = xmallocz(label_width);
memset(padding, ' ', label_width);
--
1.9.0-293-gd838d6f
next prev parent reply other threads:[~2014-03-12 21:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-12 21:19 [PATCH v2 0/4] status: allow label strings to be translated Junio C Hamano
2014-03-12 21:19 ` [PATCH v2 1/4] wt-status: make full label string to be subject to l10n Junio C Hamano
2014-03-12 21:19 ` Junio C Hamano [this message]
2014-03-12 21:19 ` [PATCH v2 3/4] wt-status: i18n of section labels Junio C Hamano
2014-03-12 21:19 ` [PATCH v2 4/4] wt-status: lift the artificual "at least 20 columns" floor Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394659174-9143-3-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
/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.
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 NNTP newsgroup(s).