gizak / termui

Golang terminal dashboard
MIT License
13.06k stars 783 forks source link

termbox-go v1.1.1 incompatibility issues and wide character related issues #322

Closed 404name closed 7 months ago

404name commented 1 year ago

I've run the examples with utf8(Chinese) characters , but can't see right result in vscode

My vscode uses the system cmd, which is in UTF-8 format like the system cmd configuration. But when running the sample file, there are two results. There is an extra space in Chinese in vscode, and it occupies the position of other characters. I don’t know if there is a solution or it’s just a problem with my vocode configuration, thanks image

404name commented 1 year ago

The termbox-go v1.1.1 version handles wide characters and solves the problem I mentioned above. The code is roughly as follows. But it seems to be incompatible with 3.1.0 of the current project, and many sample files are out of order.

https://github.com/nsf/termbox-go/blob/master/api_windows.go#L121

for _, char := range diff.chars {
if runewidth.RuneWidth(rune(char.char)) > 1 {
char.attr |= common_lvb_leading_byte
chars = append(chars, char)
chars = append(chars, char_info{
char: char.char,
attr: char.attr | common_lvb_trailing_byte,
})
} else {
chars = append(chars, char)
}
}

image

404name commented 1 year ago

I got a perfect solution, if you encounter a situation similar to mine, and it is a windows platform. It is necessary to change the termbox-go version of this project and use utf-8 encoding to run. At the same time, it is necessary to delete the processing of adding spaces to wide characters in the Render() function of termbox-go (this is for GBK, utf-8 does not need it)

there are two problem i cant resolve

so here i just Modify locally

  1. copy the filehttps://github.com/nsf/termbox-go/blob/2ff630277754813b198ae96036e28e254d2c72bf/api_windows.go
  2. replace your local file$GOPATH\pkg\mod\github.com\nsf\termbox-go@v0.0.0-20190121233118-02980233997d\api_windows.go
  3. Delete lines 130 to 134
  4. run before exec.Command("chcp","65001") If the system default encoding is gbk

by doing so,Any cmd window on the windows platform can be executed correctly

gizak commented 7 months ago

@404name Hi I bumped termbox version in master branch, things should be fixed.