Skip to content

sshd/terminal: Add fullwidth check for CJK in visualLength#339

Merged
shazow merged 1 commit intoshazow:masterfrom
yumaokao:cjk-fullwidth
Apr 2, 2020
Merged

sshd/terminal: Add fullwidth check for CJK in visualLength#339
shazow merged 1 commit intoshazow:masterfrom
yumaokao:cjk-fullwidth

Conversation

@yumaokao
Copy link
Copy Markdown

Fix for #336,

Copy link
Copy Markdown
Owner

@shazow shazow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'll have to try it out. Any interest in trying to submit this upstream to https://pkg.go.dev/golang.org/x/crypto/ssh that this is forked from?

default:
length++
kind := width.LookupRune(r).Kind()
if kind == width.EastAsianFullwidth || kind == width.EastAsianWide {
Copy link
Copy Markdown
Owner

@shazow shazow Mar 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we don't check the kind?

Does it make sense for this calculation to only happen for EastAsian runes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't check the kind, the cursor will move half steps than needed in fullwidth words. then leads to #336.

According to Halfwidth_and_fullwidth_forms in wiki,

Unicode assigns every code point an "East Asian width" property.

Terminal emulators can use this property to decide if a character should consume one or two "columns" when figuring out tabs and cursor position.

It's a property for every runes, there are ASCII characters in fullwidth (e.g. "AB" not "AB").
Kind indicates the type of width property.

@shazow
Copy link
Copy Markdown
Owner

shazow commented Mar 21, 2020

Looks great, I just want to take some time to test it with a few different terminals then I'll merge.

If you're at all interested in trying to upstream these changes, that would be quite helpful too. :)

@shazow
Copy link
Copy Markdown
Owner

shazow commented Mar 30, 2020

Sorry haven't gotten around to testing and merging this yet.

Also just stumbled on this project, do you think it would be helpful for generalizing this logic? https://github.com/rivo/uniseg

@shazow
Copy link
Copy Markdown
Owner

shazow commented Apr 2, 2020

Just had a chance to test this, it even fixes our indent bug we had with emoji rendering! Fantastic. Thank you. :)

@shazow shazow merged commit 2fb8914 into shazow:master Apr 2, 2020
@shazow
Copy link
Copy Markdown
Owner

shazow commented Apr 2, 2020

@yumaokao Again, I highly encourage you to upstream this change to https://github.com/golang/crypto, that's a great fix.

@shazow
Copy link
Copy Markdown
Owner

shazow commented Mar 27, 2021

@yumaokao Hi there, hope you're well. Any chance I can work with you to upstream this fix to https://github.com/golang/term (new package)? I'd like to get it done but technically you're the copyright holder of the change and I think we'd need you to sign the golang CLA to do that.

@yumaokao
Copy link
Copy Markdown
Author

@shazow Sure, but don't know how to achieve it cause I barely program in golang. And my thought is that the change was contributed to ssh-chat, so you could have it upstream or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants