mirror of https://github.com/gizak/termui.git
Strip dot when width is not enough to display
This commit is contained in:
parent
66f1319170
commit
150c0ce27e
12
helper.go
12
helper.go
|
@ -25,6 +25,11 @@ const (
|
||||||
AttrReverse
|
AttrReverse
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
dot = "…"
|
||||||
|
dotw = rw.StringWidth(dot)
|
||||||
|
)
|
||||||
|
|
||||||
/* ----------------------- End ----------------------------- */
|
/* ----------------------- End ----------------------------- */
|
||||||
|
|
||||||
func toTmAttr(x Attribute) tm.Attribute {
|
func toTmAttr(x Attribute) tm.Attribute {
|
||||||
|
@ -39,5 +44,10 @@ func trimStr2Runes(s string, w int) []rune {
|
||||||
if w <= 0 {
|
if w <= 0 {
|
||||||
return []rune{}
|
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, "…"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue