diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-01-09 04:53:04 +0100 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-01-09 04:53:04 +0100 |
commit | f5baabc17cefbcbff251dcec44b536f8d86bab3e (patch) | |
tree | 9312aa2669c9a7c45da5b3b553bf3ef1e0a48e0d | |
parent | c94b1cf8211f1325f8eb394cea7b466beeec4b97 (diff) |
fix condition truncation for languages with double width codepoints1.0
-rw-r--r-- | we.go | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -21,6 +21,7 @@ import ( "unicode/utf8" "github.com/mattn/go-colorable" + "github.com/mattn/go-runewidth" ) type configuration struct { @@ -450,11 +451,9 @@ func formatCond(cur []string, c cond, current bool) (ret []string) { } else { icon = i } - desc := fmt.Sprintf("%-15.15v", c.WeatherDesc[0].Value) - if current { - desc = c.WeatherDesc[0].Value - } else if lastRune, size := utf8.DecodeLastRuneInString(desc); lastRune != ' ' { - desc = desc[:len(desc)-size] + "…" + desc := c.WeatherDesc[0].Value + if !current { + desc = runewidth.Truncate(runewidth.FillRight(desc, 15), 15, "…") } ret = append(ret, fmt.Sprintf("%v %v %v", cur[0], icon[0], desc)) ret = append(ret, fmt.Sprintf("%v %v %v", cur[1], icon[1], formatTemp(c))) |