go-runewidth icon indicating copy to clipboard operation
go-runewidth copied to clipboard

Wrong width reported for some characters

Open marcopaganini opened this issue 5 years ago • 2 comments

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.

marcopaganini avatar Dec 28 '19 04:12 marcopaganini

As far as I tried to copy above into terminal, there are three letters in the string.

terminal7

So go-runewidth works fine (return 3 for the 2nd rows) for me.

mattn avatar Jan 09 '20 09:01 mattn

for reference, here's the go playground link, and the output screenshot

https://play.golang.org/p/iTnyFO4ML26

image

ghostsquad avatar Jun 29 '20 03:06 ghostsquad