Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese character width occupation problem #245

Open
404name opened this issue Jan 3, 2023 · 3 comments
Open

Chinese character width occupation problem #245

404name opened this issue Jan 3, 2023 · 3 comments

Comments

@404name
Copy link

404name commented Jan 3, 2023

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

When I change the hello world in the example program to Chinese, it is normal in the terminal that comes with the windows system, but in the cmd of vscode and goland, there is an extra space in the middle of the Chinese that occupies three widths (both used system terminal and utf-8 encoding). I'm very confused about this.

image

@404name
Copy link
Author

404name commented Jan 3, 2023

gbk is correct, utf-8 will have one more space in some environments

I found the problem. When dealing with wide characters, space adaptation should be added. Under gbk, chcp 936 is normal here, and under utf-8 chcp 65001, there is one more space, and the logic of deleting and adding spaces is fine。So don't switch cmd to utf-8. (maybe it's just my local problem)

// https://github.com/nsf/termbox-go/blob/master/api_windows.go
if runewidth.RuneWidth(rune(char.char)) > 1 {
    char.attr |= common_lvb_leading_byte
    chars = append(chars, char)
    // here 
    chars = append(chars, char_info{
	    char: char.char,
	    attr: char.attr | common_lvb_trailing_byte,
    })
} 

@404name
Copy link
Author

404name commented Jan 3, 2023

bug description:It seems that wide characters do not need to add spaces under UTF-8 encoding? (I verified it locally, not sure if it is the case on other platforms or other machines)

how to solve

expected:Is it possible to judge whether the current chcp is equal to 65001 (UTF-8), and consider adding spaces? [I know that there may be many encoding formats that are inconvenient to adapt, just ask questions when encountering this situation]

related environment
platform:windows
terminal: cmd | vscode| goland

@ydzhou
Copy link

ydzhou commented Jan 9, 2024

I do not have this problem when using tbprint.
https://github.com/ydzhou/pine/blob/f69443a87ad8c6754e305415dee930447fcdbb9f/internal/renderUtil.go#L55

My editor can print Chinese or other UTF-8 characters as expected (without any spacing in-between)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants