From c704dcd9d4a103a999da383923ba229f6ea07b83 Mon Sep 17 00:00:00 2001 From: c-bata Date: Fri, 22 Jun 2018 17:04:55 +0900 Subject: [PATCH] Refactor truncate string --- completion.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/completion.go b/completion.go index 283f0fb..c4a1791 100644 --- a/completion.go +++ b/completion.go @@ -141,12 +141,8 @@ func formatTexts(o []string, max int, prefix, suffix string) (new []string, widt } else if x > width { x := runewidth.Truncate(o[i], width, shortenSuffix) // When calling runewidth.Truncate("您好xxx您好xxx", 11, "...") returns "您好xxx..." - // But the length of this result is 10. So we need to insert a space. - if l := runewidth.StringWidth(x); l < width { - spaces := strings.Repeat(" ", width - l) - x += spaces - } - n[i] = prefix + x + suffix + // But the length of this result is 10. So we need fill right using runewidth.FillRight. + n[i] = prefix + runewidth.FillRight(x, width) + suffix } } return n, lenPrefix + width + lenSuffix