summaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2013-12-19 11:43:19 -0800
committerJunio C Hamano <gitster@pobox.com>2014-03-12 14:08:05 -0700
commit335e8250124aea055cbe4fb8a2268fa9e2f34439 (patch)
treef83f53beb468d2bb514b42dec42c9531ef35793b /wt-status.c
parentd52cb5761a0e92e6051ea92edc7ae96fb6dca78f (diff)
downloadgit-335e8250124aea055cbe4fb8a2268fa9e2f34439.tar.gz
wt-status: extract the code to compute width for labels
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/wt-status.c b/wt-status.c
index 9cf70287d9..db98c52d45 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);