elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.62k stars 300 forks source link

lackEOLRune cause garbled #1184

Open mrlzh opened 3 years ago

mrlzh commented 3 years ago

elvish write '\u23ce' while doing setupVT.

const (
    lackEOLRune    = '\u23ce'
    lackEOL        = "\033[7m" + string(lackEOLRune) + "\033[m"
    enableSGRMouse = false
)
s += fmt.Sprintf("\033[?7h%s%*s\r \r", lackEOL, width-wcwidth.OfRune(lackEOLRune), "")

This will cause garbled while terminal is set charset gbk. elvish shows:

~/Desktop/elvish-0.14.1>
鈴?
krader1961 commented 3 years ago

This will cause garbled while terminal is set charset gbk.

AFAIK, Elvish only supports (albeit implicitly) Unicode locales and the UTF-8 encoding for charsets. This is (sort of) documented at https://elv.sh/ref/language.html. It is a consequence of Elvish being implemented in a language that itself only treats Unicode as a first class charset.

P.S., Thanks for opening this issue. It caused me to read https://en.wikipedia.org/wiki/GBK_(character_encoding). Even though I'm a native English speaker I was aware of GB2312 but not the GBK charset.

krader1961 commented 2 years ago

@xiaq, This should be closed since I'm pretty certain Elvish will never have support for legacy, non-Unicode, charsets. The only thing we might want to do is issue a warning if the locale is not UTF-8.