From 5881041fcdbd0b4a6f4ca3740b9839a0c9181a5e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 25 Jul 2023 09:40:58 +0530 Subject: [PATCH] Ensure shortduration is no more than 8 chars --- tools/utils/humanize/times.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/utils/humanize/times.go b/tools/utils/humanize/times.go index 9d6513794..7d32a622b 100644 --- a/tools/utils/humanize/times.go +++ b/tools/utils/humanize/times.go @@ -133,7 +133,7 @@ func zero_pad(x string) string { return x } -// Render the duration in exactly 8 chars +// Render the duration in exactly 8 visual chars func ShortDuration(val time.Duration) (ans string) { if val >= time.Second { if val > Day { @@ -160,6 +160,8 @@ func ShortDuration(val time.Duration) (ans string) { } if w := wcswidth.Stringwidth(ans); w < 8 { ans = strings.Repeat(" ", 8-w) + ans + } else if w > 8 { + ans = wcswidth.TruncateToVisualLength(ans, 8) } return }