Update unicode table to the version 15.1.0 - #744
Conversation
Pull Request Test Coverage Report for Build 7796909910
💛 - Coveralls |
| #define ENC_NARROW 3 | ||
|
|
||
| static int widths_len = 2*38; | ||
| static int widths_len = 2*820; |
There was a problem hiding this comment.
Doing a linear search over 820 items might slow. Should we think of using a more efficient data structure or am I overthinking this?
There was a problem hiding this comment.
I'm even thinking about depreciation of C code and migration on `wcwidth.
It became global standard, handle multiple unicode versions and since author allow to copy-paste unicode version detect logic - we can better handle different terminals.
Re-implementation of unicode tables in C or migration on different language (like rust) at this moment is too painful
There was a problem hiding this comment.
detecting things about the terminal is tricky because the text calculations are separated from the screen instance. If someone is connecting to an urwid app over ssh like the twisted ssh example how do we know which unicode version detection to use? (there can be many users attached each with their own screen)
There was a problem hiding this comment.
but, using an existing library for the width calculation sounds like a great idea (assuming it doesn't make calculations significantly slower)
There was a problem hiding this comment.
And simple copy-paste of logic and content (even if separate generated) looks strange.
We can use binary search, it is faster.
There was a problem hiding this comment.
I checked: for current release we can use binary search and later we can migrate C part to rust and use upstream libraries for char width both in python and binary.
There was a problem hiding this comment.
Re: use of wcwidth - good idea to do so, but I suggest you have a look at a recent issue posted by the author on his github, where he discusses the limits of UNICODE_VERSION jquast/wcwidth#104
the tl dr is that it's challenging to fix unicode version compatibility issues at the app layer, and the way forward is to get terminal emulator authors to stay up to date with the latest unicode version.
There was a problem hiding this comment.
Re: use of wcwidth - good idea to do so, but I suggest you have a look at a recent issue posted by the author on his github, where he discusses the limits of UNICODE_VERSION jquast/wcwidth#104
I fully understand that issue, but it also has limitations: in case of widget decorations, incorrect symbols length of decorated widget will produce incorrect decorations length.
Technically we can play "stupid" and go forward with the last unicode version tables, since only few terminals at this moment fully stuck at unicode 12.
the tl dr is that it's challenging to fix unicode version compatibility issues at the app layer, and the way forward is to get terminal emulator authors to stay up to date with the latest unicode version.
There was a problem hiding this comment.
Understood. Makes sense to update the tables. I am curious, why update to v.12 and not the latest v.15.1?
There was a problem hiding this comment.
Originally went to the most supported.
After rethinking on weekends went to the 15.1
Technically we have only 1 fully working solution: ask terminal for cursor position after each double width character and add space if it rendered single width, but this solution is extremely expensive and works only with RawDisplay.
ulidtko
left a comment
There was a problem hiding this comment.
A few questions.
- Why are we duplicating the logic of Python's built-in stdlib? https://docs.python.org/3/library/unicodedata.html#unicodedata.east_asian_width
- Can we get rid of the C impl?.. It has caused build issues which'd not exist in a pure-python package.
- Can we compress the table by assuming width 1 for absent entries?
>>> import sys; print('Python %s on %s' % (sys.version, sys.platform))
Python 3.11.4 (main, Dec 7 2023, 15:43:41) [GCC 12.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.15.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 8.15.0
Python 3.11.4 (main, Dec 7 2023, 15:43:41) [GCC 12.3.0] on linux
>>> import unicodedata
>>> unicodedata.unidata_version
'14.0.0'
|
|
Small extra details about unicodedata in python core:
|
|
https://docs.python.org/3/library/unicodedata.html#unicodedata.east_asian_width and other functions in unicodedata library are not sufficient for measuring zero-width, combining, VS-16 emoji, or ZWJ emoji sequences. There is a lot of work done in wcwidth library (update-tables.py) to transfer unicode.org data files into efficient lookup tables and make corrections in their categorization that the unicodedata library does not perform. (I too would like to use the standard python library to measure characters for a terminal, I do hope to work on that this year jquast/wcwidth#94) A basic example, In this case, there is insufficient data in the std unicodedata library measure the width of this emoji, while, |
c40fc53 to
0750bee
Compare
|
Switched python implementation to the |
| if o in {0xE, 0xF}: | ||
| width = wcwidth.wcwidth(chr(o), UNICODE_VERSION) | ||
| if width < 0: | ||
| return 0 |
There was a problem hiding this comment.
urwid using only positive width
Partially fix render of emoji * Use 2-dimensional array in C code and get rid of len constant * Adjust C implementation: all codes < 32 are not printable: It's not ASCII chars * Partially apply clang-format to the helper source * Use `wcwidth` for python character width calculation
0f585c1 to
5424506
Compare
|
Looks like Unicode problem is raising. I have to merge this PR and later work on proper Unicode handling in the internals. |
Partially fix render of emoji
Checklist
masterorpython-dual-supportbranchtoxsuccessfully in local environmentPartial #225