mattn / go-runewidth

wcwidth for golang
MIT License
609 stars 94 forks source link

incorrect rune width for box drawing characters in east asian encoding #49

Closed jesseduffield closed 3 years ago

jesseduffield commented 3 years ago

When using an east asian encoding, the following runes are given a width of 2 but they should be 1: ─┌└┐┘│.

To reproduce:

export LC_CTYPE="ja_JP.UTF-8"
(in go program)
runewidth.RuneWidth('─') // returns 2

looking at the runewidth_table.go file, the culprit is {0x24EB, 0x254B} in the ambiguous table. I'm not sure how to update this; the file is auto-generated.

In terminal apps which render box characters this can lead to broken rendering: image

Let me know if there's anything else I can add. Thanks :)

Milly commented 3 years ago

Box Drawing characters (u2500 to u257f) has a Ambiguous East Asian Width. It is Unicode specification. I think the implementation of the go-runewidth is correct.

The solution to the problem is to configure the terminal application correctly AND use the correct font.

Alternatively, add an option to draw lines with only ASCII characters.

mattn commented 3 years ago

Could you please try

export RUNEWIDTH_EASTASIAN=0
mattn commented 3 years ago

Or

runewidth.DefaultCondition.EastAsian = false
jesseduffield commented 3 years ago

@mattn thanks I'll give runewidth.DefaultCondition.EastAsianWidth = false a go. Feel free to close