gbk panic:character set not supported
lsw45 opened this issue · 5 comments
The OS‘s env:
#echo $LANG
zh_CN.gbk
And the code:
t.keytimer = time.NewTimer(time.Millisecond * 50)
t.charset = "UTF-8"
t.charset = getCharset()
if enc := GetEncoding(t.charset); enc != nil {
t.encoder = enc.NewEncoder()
t.decoder = enc.NewDecoder()
} else {
return ErrNoCharset
}
@gdamore This is not my OS,I can't change LANG to UTF-8 or any other env. how to fix???
GBK is a legacy 16-bit encoding. Very surprising to see it -- would have expected GB18030 -- which is the newer Unicode compatible set.
I don't think the encoding library supports GBK at this time. However, there is a standard encoding/simplifiedchinese package that might be useful.
I don't really know anything about these encoding or character sets. I'll look to see if there is something easy I can do.
Good news.
There is already a function called "RegisterEncoding" in tcell, and there is a GBK text encoding package.
So you can do:
import "golang.org/x/text/encoding/simplifiedchinese"
tcell.RegisterEncoding("GBK", simplifiedchinese.GBK)
You might also do so for GB18030 and HZGB2312 if you need to.
Also if you don't care about binary size, I have a pre-baked package you can just import:
import "tcell/v2/encoding"
This registers pretty much the entire set of reasonable ISO 8859, East Asian, and Cyrillic (KOI8) encodings.
Oh, you have to do "encoding.Register()" to get them registered. :-)
And if you pull from master, you'll get a change I just made which means all you have to do is import the tcell/v2/encoding package to get them all.