nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.67k stars 373 forks source link

Chinese characters support issue #243

Open ns-cn opened 2 years ago

ns-cn commented 2 years ago

My terminal application using github.com/jroimartin/gocui which based on termbox-go, but I found some display issues.

termbox.SetCell(x, y int, ch rune, fg, bg Attribute)

The following issues are caused by setCell with Chinese character.

image
nsf commented 2 years ago

When working with characters that occupy more than one cell, you have to handle it yourself. There are handy libs like: https://github.com/mattn/go-runewidth, which can help you with that. Sadly I don't have much experience with it. There are examples contributed by other people though which use runewidth lib:

Maybe try running them with Chinese input/text and if it works properly for you then look at the code. And I would suggest looking at alternative UI libs as well, such as https://github.com/rivo/tview. Proper text handling is complicated and most libs I saw use the mentioned above runewidth lib, e.g.: https://github.com/rivo/tview/blob/0e6b21a48e9606d07c6bf79171d6ce05d159f9f9/util.go#L456