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

Fix rendering of multi-byte strings #231

Merged
merged 1 commit into from
Jan 14, 2021
Merged

Conversation

mattn
Copy link
Contributor

@mattn mattn commented Dec 14, 2020

@mattn
Copy link
Contributor Author

mattn commented Dec 14, 2020

This fix issue that trembox-go on Windows Terminal does not work correctly with multi-byte strings.

@scrouthtv
Copy link
Collaborator

First of all thanks for the PR!
I have some questions:
I suppose an example for multibyte characters are chinese characters, e. g. .
I am testing this character using editbox.go provided in the _demos folder.

Current status with nsf/master is that multibyte characters overdraw some things:
editboxmaster

Now using your fix, the same scenario using Windows 10 v19041 looks like this:
editboxfix

Three things I've noticed:

  1. The bar at the end moves one character to the right
  2. There is a space after the multibyte character
  3. The cursor is off by one (I can't go further to the right, and deleting deletes the character right off the cursor, not left of it)

Now regarding 2. I thougt there is an issue with multibyte characters and my font, however this is the very same window but vim open and the character renders properly:
image

Do you have any clue how to further fix these?
I checked editbox.go and

  • The bar at the end is drawn at an arbitrary position using termbox.SetCell (see lines 245 and 254)
  • The character width is calculated using runewidth.RuneWidth (see line 13)

I've run all my tests in the new Windows Terminal, inserting multi-byte characters also does not work in a plain cmd.exe for me:
editboxplaincmd
Notice how I first successfully insert the chinese character in the Windows Terminal, and then run the very same test in a plain cmd.exe but I can't insert the character using Insert.
I think this one is an issue with cmd.exe that we can't fix, since I can also not insert a multibyte character in the plain cmd prompt using Insert. I just noticed that raw_input.go is broken on Windows, so I can't test that.

I also would like to know whether this fix is backwards compatible with anything older than Windows 10 (7, 8, ...)?

Thank you for your patience and have a nice day!

@mattn
Copy link
Contributor Author

mattn commented Dec 14, 2020

What is your console code page? editbox.go should replace bars with ascii-borders if using CJK.

image

@scrouthtv
Copy link
Collaborator

scrouthtv commented Dec 14, 2020 via email

@mattn
Copy link
Contributor Author

mattn commented Dec 15, 2020

It's an East Asian Ambiguous Width. The width of bar might be changed with locales you are using. Also the width is not compatible on Windows and wcwidth(2). go-runewidth follows wcwidth(2).

@mattn
Copy link
Contributor Author

mattn commented Dec 15, 2020

Anyway, this is not related on this pull-request.

@scrouthtv
Copy link
Collaborator

Thank you. But what is about the cursor issue and the spacing after the cjk character (both in the second gif)? Am I the only one having it? Your screenshot doesn't look like it.

@mattn
Copy link
Contributor Author

mattn commented Dec 15, 2020

What value do you get with chcp on cmd.exe ?

@scrouthtv
Copy link
Collaborator

Active codepage: 437

@mattn
Copy link
Contributor Author

mattn commented Dec 17, 2020

Could you please try this code with go run ?

package main

import (
	"fmt"
)

func main() {
	fmt.Println(`
┌──┐
│在│
└──┘
`)
}

image

@mattn
Copy link
Contributor Author

mattn commented Dec 17, 2020

This is result on Linux (mintty terminal)

image

@scrouthtv
Copy link
Collaborator

image
PowerShell in the new Windows Terminal

@scrouthtv
Copy link
Collaborator

scrouthtv commented Dec 17, 2020

image
cmd.exe and pwsh.exe in the old conhost

@mattn
Copy link
Contributor Author

mattn commented Jan 14, 2021

@nsf the issue @scrouthtv mentioned is another issue that must be fixed. So let's merge this?

@scrouthtv scrouthtv merged commit d04385b into nsf:master Jan 14, 2021
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

Successfully merging this pull request may close these issues.

2 participants