Skip to content

Conversation

@jquast
Copy link

@jquast jquast commented Jan 26, 2026

  • Enhanced 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 in wcwidth>=0.3. It no longer returns -1 for control characters like previous wcswidth function, 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 in wcwidth>=0.3, providing these same benefits.
  • A minor bugfix or improvement, but certainly a change, is that display_center() now matches standard python str.center()'s famously undocumented "parity-odd" spacing.

Closes #226

-1
"""
return int(wcwidth(char))
return wcwidth.wcwidth(char)
Copy link
Author

@jquast jquast Jan 26, 2026

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
Copy link
Author

@jquast jquast Jan 26, 2026

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)

Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wcwidth 0.2.14 breaks doctest

1 participant