-
Notifications
You must be signed in to change notification settings - Fork 758
Improve support for emojis+cursor w/grapheme clustering #2045
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
base: main
Are you sure you want to change the base?
Conversation
a244ba5 to
918a8eb
Compare
95e89b0 to
953cfe5
Compare
|
|
||
| This offers code coverage without mocks, but using real tty features of the natural "live" call to | ||
| PromptSession() and session.prompt. prompt_toolkit sees a real terminal through use of shared | ||
| pty_accessories module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might show some improved test coverage for this reason
feel free to extend this test to get those previously unreachable lines
| for target in [(40, 120), (10, 40), (3, 10)]: | ||
| _setwinsize(fd, *target) | ||
| time.sleep(0.05) | ||
| assert _get_size(fd) == target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more advance version of this test could help verify screen draw reactions and effects of resize on SIGWINCH signal, for example.
| time.sleep(0.2) | ||
| assert ( | ||
| extract_output(read_until_marker(fd, ":END", timeout=10.0)) == grapheme * 5 | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are simplified but provide pty coverage, the highest level possible exercise, which is nice because it is also necessary to test these changes.
More improvement could be done to also verify screen draw effects of the REPL, these only verify output after sending return key, where repl integration print()'s result.
4d6d2ac to
8aeef93
Compare
**Problem** Test sequence (copy and paste into any REPL/edit area)::
π¨βπ©βπ§ π©ββ€βπ¨ π©βπ»ππΏ β€οΈβ π―π΅π©πͺ cafeΜ ninΜo AΜoΜΜ£ δΈζ!.
Moving the cursor over and around emojis get strange. insertions become
chaotic. Cursor position becomes indeterminate (even negative!), input
result becomes more corrupted with user confusion as draws become
corrupted. This is briefly described in prompt-toolkit#274 by @jonathanslenders:
> Notice that it still requires multiple cursor movements (left/right
arrow) to move across these characters.
**Solution**: Close prompt-toolkit#274 "Handle decomposed unicode characters" (2018)
through careful integration of new functions,
[wcwidth.iter_graphemes](https://wcwidth.readthedocs.io/en/latest/intro.html#iter-graphemes)
and
[wcwidth.grapheme_boundary_before](https://wcwidth.readthedocs.io/en/latest/api.html#wcwidth.grapheme_boundary_before).
getting there, working on a PTY test suite
I don't feel comfortable changing so much code for a large library
without also including more detailed tests -- i keep fixing all errors
with TDD/automatic tests, but when using it interactively, the cursor
position is out of control
8aeef93 to
aed10aa
Compare
Problem
Copy and paste this test sequence to call
prompt_toolkit.prompt('Give me some input: '):Moving the cursor over and around emojis get strange. insertions become chaotic. Cursor position becomes indeterminate (even negative!), input result becomes more corrupted with user confusion as draws become corrupted. This is briefly described in #274 by @jonathanslenders:
wcwidth-integration-before-trimmed.mp4
Solution
Close #274 "Handle decomposed unicode characters" (2018) through careful integration of new functions, wcwidth.iter_graphemes and wcwidth.grapheme_boundary_before.
wcwidth-integration-after.mp4
Details