-
Notifications
You must be signed in to change notification settings - Fork 51
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
Incorrect marker width calculation of Unicode symbols can cause markers to not be displayed #287
Comments
Well this would have never occurred to me :) Can you try replacing Line 38 in 8fdebc3
width += len(label.encode("utf-8")) My quick tests indicate that might over-report the length of emojis for display purposes, but it does seem to reliably report a length of 1 for the common ASCII characters, and I'm guessing it would at least fix the problem of the column being too narrow. If that works, we can look at a little more logic to triangulate the best display width for emojis -- I really don't want to add a dependency to VIT for something that's probably a minor and rarely used feature. |
I'm not surprised, it's great that emojis are even supported without any extra hassle! I'm only just getting started with vit/task but I already feel like it's gonna change my life hehehe. So
It looks like there is also a built-in
So based on this information one could just add one extra width for every wide character in the label like so:
If you think the
So a minimal, import-free hack solution could be:
|
I wasn't so worried about importing I decided to create a simple test, where I emulated the If you can find any info on the performance of those lookups, or want to construct a more robust test, I'd love to hear what you find! |
I doubt there's a huge overhead for character type lookup, Already found a minor issue with some symbols (such as |
@kevinstadler thanks again for all your work on this! BTW, if you're loving TaskWarrior/VIT, you might want to check out https://github.com/thehunmonkgroup/onenote as well -- I wrote that out of necessity, and can't live w/o it now! |
Related: In TW itself, we recently had to update the unicode width character determination to support newest emojis :) GothenburgBitFactory/taskwarrior#2333 |
@thehunmonkgroup cool, I'll have a look! Is there a user group / chat for vit somewhere? I'm having trouble getting vit to use the taskwarrior report coloring, and the parameters in the |
Describe the bug
Emoji marker display works out of the box, and normally emojis are displayed correctly, with most taking up the width of 2 ASCII characters each (I'm on
GNU bash, version 5.0.16(1)-release (x86_64-apple-darwin17.7.0)
).However, when the marker column of a report contains emoji markers but no ASCII-markers (or column header label) wider than 1 character, then the required column width is incorrectly calculated to be 1 character wide, which does not leave enough space for the emoji markers to be displayed.
(I've only tested this on a small number of emojis but presumably the bug also applies to all other non-width-1 Unicode characters/symbols.)
To Reproduce
Open any report using the following marker config
Expected behavior
Emoji markers should be displayed by allocating a wide enough marker column based on a correct calculation of the marker width (which might have to take into account properties of the console/font set).
Suggested fix
The mis-calculation happens in line 38 here, which assumes that every String character is exactly one display character wide:
vit/vit/formatter/markers.py
Lines 34 to 41 in 8fdebc3
Python-Curses doesn't seem to provide a way to perform a correct width calculation of Unicode symbols, so solving this might require recourse to an external library dependency (in particular https://github.com/jquast/wcwidth)
The text was updated successfully, but these errors were encountered: