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

Chinese characters support issue

Open ns-cn opened this issue 2 years ago • 1 comments

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.

  • It works well when I tried to input Chinese characters one by one ,but characters overlapped likes this

my input is [中文]. image

  • Some characters disappear when I tried to input more than one Chinese characters , like this

my input is [中文中文].

image

ns-cn avatar Sep 01 '22 08:09 ns-cn

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:

  • https://github.com/nsf/termbox-go/blob/master/_demos/hello_world.go
  • https://github.com/nsf/termbox-go/blob/master/_demos/editbox.go

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

nsf avatar Sep 01 '22 11:09 nsf