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

Corrected cursor positioning on inputs with full-width (2 column) characters #817

Merged
merged 4 commits into from Jul 14, 2020

Conversation

@rybarczykj
Copy link
Contributor

rybarczykj commented Jul 1, 2020

This addresses issue #749. It should now be fixed for normal input as well as stdin input.

Before:
widetextbefore

After:
widetextafter

Also, because the issue with width aware text wrapping still exists (#731), it gets a little weird when you exceed one line. Still, I think the cursor is in the correct spot. In the below example the un-wrapped part is '67890'. The cursor seems right despite the text not wrapping.
widetextwrap

- Works with normal input and stdin input
- There still are issues with line wrapping when using full-width chars
@rybarczykj rybarczykj changed the title Correct cursor position on input with full-width (2 column) characters Corrected cursor positioning on inputs with full-width (2 column) characters Jul 1, 2020
@thomasballinger
Copy link
Member

thomasballinger commented Jul 4, 2020

This is great, nice.

Could you check whether this works + whether the .width method exists in the lowest required version of curtsies, as defined in the bpython setup.py?

This might be good as is, but some other pieces to look at:

  • when I paste "he above, there are" into the save dialog, I get greater-than signs. What's up with that?
  • the cursor in input("he above, there are ") isn't aligned yet
  • wrapping, as you've pointed out
  • F7 works, great!
  • Are there any examples you can find that are a the wrong width, as per https://jeffquast.com/post/terminal_wcwidth_solution/? If we we should open an issue and you might look at this too.
@thomasballinger
Copy link
Member

thomasballinger commented Jul 4, 2020

Another thing, it'd be great to close #731 once this or another PR supersedes it for fixing wrapping

@thomasballinger
Copy link
Member

thomasballinger commented Jul 5, 2020

Could you confirm that this fixes #605 too?

@thomasballinger
Copy link
Member

thomasballinger commented Jul 5, 2020

and #670!

rybarczykj added 2 commits Jul 6, 2020
from 0.1.18 to 0.2.0 so as to allow .width
@rybarczykj
Copy link
Contributor Author

rybarczykj commented Jul 9, 2020

when I paste "he above, there are" into the save dialog, I get greater-than signs. What's up with that?

Oh yeah, that's weird. I think I'll leave that for now though. It seems outside of scope.

the cursor in input("he above, there are ") isn't aligned yet

Should be fixed with commit 9e380

wrapping

Yep, inputs with wide chars now work fine until you exceed one line. I'll look at this next.

#605

This seems fixed now, at least for all non-emoji combined characters I could find. Some emojis that combine characters do actually break it, but that's obviously not very urgent. For reference the emoji thing is a known wcwidth issue.

- len(self.current_line)
+ self.cursor_offset
self.current_cursor_line_without_suggestion.width
- wcswidth(self.current_line)

This comment has been minimized.

@thomasballinger

thomasballinger Jul 13, 2020

Member

What's the distinction here between the wcswidth and .width, are some of these FmtStrs and some of them plain strs? (and if it's not clear, could you add comments to the definitions or initialization lines?)

@thomasballinger
Copy link
Member

thomasballinger commented Jul 13, 2020

Sorry about the delay here. This looks good, only thing left is to clarify why we're using both techniques instead of just one or the other, since dropping either (removing wcswidth when we haven't added it to setup.py, or eliminating the need for the Curtsies upgrade) would be nice. Also, assuming we do keep the wcwidth library, it should be added to the explicit setup.py dependencies.

@rybarczykj
Copy link
Contributor Author

rybarczykj commented Jul 13, 2020

Oh yep. I had used both because some of those objects were FmtStr and some str, but I can definitely make it only use wcswidth() to avoid the curtsies upgrade for now, because FmtStr.width is essentially a wrapper for wcswidth(FmtStr.s). I'll do that and update the setup.py

- Use wcswidth(FmtStr.s) instead of FmtStr.width
@thomasballinger thomasballinger merged commit 8e25e01 into bpython:master Jul 14, 2020
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.