Skip to content

Commit

Permalink
fix condition truncation for languages with double width codepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
schachmat committed Jan 9, 2016
1 parent c94b1cf commit f5baabc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions we.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"unicode/utf8"

"github.com/mattn/go-colorable"
"github.com/mattn/go-runewidth"
)

type configuration struct {
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit f5baabc

Please sign in to comment.