go-runewidth
go-runewidth copied to clipboard
Wrong width reported for some characters
It appears that StringWidth reports the length of certain runes incorrectly. The problem seems to be centered around languages used primarily in India (Tamil, Telugu, and Hindi are examples).
Sample program that shows the problem:
package main
import (
"fmt"
"github.com/mattn/go-runewidth"
"strings"
)
func main() {
words := []string{
"English",
"हिन्द",
"தமிழ்",
"ไทย",
"עברית",
}
for _, w := range words {
max := 12 - runewidth.StringWidth(w)
fmt.Printf("|%s%s|\n", w, strings.Repeat(" ", max))
}
}
The output is shows the misalignment in the 2nd and 3rd rows (sorry, but pasting here won't work since Github seems to force "Liberation Mono" as the monospace font and this font appears to have its own issues). I've tried this on terminals, browsers, etc, always with similar results.
As far as I tried to copy above into terminal, there are three letters in the string.

So go-runewidth works fine (return 3 for the 2nd rows) for me.
for reference, here's the go playground link, and the output screenshot
https://play.golang.org/p/iTnyFO4ML26
