Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 335e825

Browse files
jrngitster
authored andcommitted
wt-status: extract the code to compute width for labels
Signed-off-by: Junio C Hamano <[email protected]>
1 parent d52cb57 commit 335e825

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

wt-status.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ static const char *wt_status_diff_status_string(int status)
292292
}
293293
}
294294

295+
static int maxwidth(const char *(*label)(int), int minval, int maxval)
296+
{
297+
int result = 0, i;
298+
299+
for (i = minval; i <= maxval; i++) {
300+
const char *s = label(i);
301+
int len = s ? utf8_strwidth(s) : 0;
302+
if (len > result)
303+
result = len;
304+
}
305+
return result;
306+
}
307+
295308
static void wt_status_print_change_data(struct wt_status *s,
296309
int change_type,
297310
struct string_list_item *it)
@@ -310,13 +323,8 @@ static void wt_status_print_change_data(struct wt_status *s,
310323
int len;
311324

312325
if (!padding) {
313-
/* If DIFF_STATUS_* uses outside this range, we're in trouble */
314-
for (status = 'A'; status <= 'Z'; status++) {
315-
what = wt_status_diff_status_string(status);
316-
len = what ? strlen(what) : 0;
317-
if (len > label_width)
318-
label_width = len;
319-
}
326+
/* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */
327+
label_width = maxwidth(wt_status_diff_status_string, 'A', 'Z');
320328
label_width += strlen(" ");
321329
padding = xmallocz(label_width);
322330
memset(padding, ' ', label_width);

0 commit comments

Comments
 (0)