From 150c0ce27e3df4cf7cebb047821fa2eb7c36943d Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 12 Mar 2015 16:57:14 +0900 Subject: [PATCH] Strip dot when width is not enough to display --- helper.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/helper.go b/helper.go index 2a7d6b1..2952cf9 100644 --- a/helper.go +++ b/helper.go @@ -25,6 +25,11 @@ const ( AttrReverse ) +var ( + dot = "…" + dotw = rw.StringWidth(dot) +) + /* ----------------------- End ----------------------------- */ func toTmAttr(x Attribute) tm.Attribute { @@ -39,5 +44,10 @@ func trimStr2Runes(s string, w int) []rune { if w <= 0 { return []rune{} } - return []rune(rw.Truncate(s, w, "…")) + sw := rw.StringWidth(s) + if sw+dotw >= w { + return []rune(rw.Truncate(s, w, "")) + } else { + return []rune(rw.Truncate(s, w, "…")) + } }