-
Notifications
You must be signed in to change notification settings - Fork 125
Improve support of emoji/flags/skin tones in monospaced_width() #227
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
| -1 | ||
| """ | ||
| return int(wcwidth(char)) | ||
| return wcwidth.wcwidth(char) |
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.
the int() wrapper was probably needed from an earlier version of wcwidth that was not typed, but it is typed now
| 11 | ||
| >>> monospaced_width('example\x80') | ||
| -1 | ||
| 12 |
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.
Related to SOFT HYPHEN: #226 (comment)
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.
'example\x80' now returns width 7 instead of -1, but removed it anyway
| padding = max(0, width - text_width) | ||
| left_padding = padding // 2 | ||
| right_padding = padding - left_padding | ||
| return fillchar * left_padding + text + fillchar * right_padding |
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.
there was a bug here, see https://jazcap53.github.io/pythons-eccentric-strcenter.html
but you never would have guessed, i made the same mistake jquast/wcwidth#188
monospaced_width()to support emoji ZWJ sequences, flags, variation selectors, skin tones, and many more languages and terminal sequences, like OSC 8 hyperlinks by using wcwidth.width new inwcwidth>=0.3. It no longer returns -1 for control characters like previouswcswidthfunction, instead they are parsed (eg. BACKSPACE,\b) for their horizontal effects, or otherwise ignored, (eg. BEL,\a).display_ljust()and related now delegate to wcwidth.ljust(), also new inwcwidth>=0.3, providing these same benefits.display_center()now matches standard python str.center()'s famously undocumented "parity-odd" spacing.Closes #226