Skip to content

Commit

Permalink
Merge pull request olekukonko#18 from lixin9311/master
Browse files Browse the repository at this point in the history
fix wrong CJK Character width.
  • Loading branch information
olekukonko committed Oct 29, 2015
2 parents 031e82a + 226b93e commit a5eefc2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ var (
)

func DisplayWidth(str string) int {
return utf8.RuneCountInString(ansi.ReplaceAllLiteralString(str, ""))
tmp := ansi.ReplaceAllLiteralString(str, "")
tmp_rune := []rune(tmp)
count := 0
for _, v := range tmp_rune {
if v > 128 {
count++
}
}
return utf8.RuneCountInString(tmp) + count
}

// Simple Condition for string
Expand Down

0 comments on commit a5eefc2

Please sign in to comment.