Improve support of emoji/flags/skin tones in monospaced_width()#227
Open
jquast wants to merge 1 commit intorspeer:mainfrom
Open
Improve support of emoji/flags/skin tones in monospaced_width()#227jquast wants to merge 1 commit intorspeer:mainfrom
jquast wants to merge 1 commit intorspeer:mainfrom
Conversation
jquast
commented
Jan 26, 2026
| -1 | ||
| """ | ||
| return int(wcwidth(char)) | ||
| return wcwidth.wcwidth(char) |
Author
There was a problem hiding this comment.
the int() wrapper was probably needed from an earlier version of wcwidth that was not typed, but it is typed now
jquast
commented
Jan 26, 2026
| 11 | ||
| >>> monospaced_width('example\x80') | ||
| -1 | ||
| 12 |
Author
There was a problem hiding this comment.
'example\x80' now returns width 7 instead of -1, but removed it anyway
jquast
commented
Jan 26, 2026
| padding = max(0, width - text_width) | ||
| left_padding = padding // 2 | ||
| right_padding = padding - left_padding | ||
| return fillchar * left_padding + text + fillchar * right_padding |
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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