Skip to content

Bugfix grapheme and East-Asian support by wcwidth>=0.5.1 integration#391

Closed
jquast wants to merge 6 commits intoastanin:masterfrom
jquast:jq/wcwidth-030-integration
Closed

Bugfix grapheme and East-Asian support by wcwidth>=0.5.1 integration#391
jquast wants to merge 6 commits intoastanin:masterfrom
jquast:jq/wcwidth-030-integration

Conversation

@jquast
Copy link

@jquast jquast commented Jan 25, 2026

  • Bugfix In _CustomTextWrap._handle_long_word(), on master branch or this branch when optional co-dependency wcwidth<0.3.0:

    • east-asian characters were measured using len() but should use width-aware self._len().
    • Tests are provided to exercise this.
  • Improve word-wrapping with unicode, starting wcwidth version 0.3.0, the wrap(), and width() functions also parse sequences pretty much the same, even a bit better by "tracking" more kinds of SGR sequences and "reducing" them a bit better on line breaks.

    • optional wcwidth>=0.5.1 handles grapheme boundaries better for many kinds of languages, or just flags and emojis and significantly improved performance over 0.2.14.

note

  • Because almost all users will not know to install the optional "wide" version, they may also have wcwidth at an older version installed by chance. hasattr() must be used for some defense of this circumstance.
    • a special test fixture is used to exercise both possibilities even when latest wcwidth is installed by a mock "wcwidth" module that pretends to be without wrap().

@jquast jquast marked this pull request as draft January 26, 2026 20:03
@jquast

This comment was marked as resolved.

@jquast jquast marked this pull request as ready for review January 27, 2026 08:18
@jquast jquast changed the title Bugfix grapheme and East-Asian support by wcwidth>=0.3.5 integration Bugfix grapheme and East-Asian support by wcwidth>=0.5.1 integration Jan 27, 2026
casted_cell = str(cell)
wrapped = [
"\n".join(wrapper.wrap(line))
"\n".join(wrapper_wrap(line))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functools.partial() was just used to help make this change clear and concise, not needed but doesn't hurt and already imported and used somewhere else

@astanin
Copy link
Owner

astanin commented Mar 4, 2026

I would be helpful to know what is the original issue this PR is trying to solve.
Input, output, expected output.

Please add or reference an issue.

@astanin astanin added the incomplete This PR requires some further changes or modifications before it can be merged. label Mar 4, 2026
@jquast
Copy link
Author

jquast commented Mar 4, 2026

That's ok, I thought the automatic tests were self-evident. the issue is yours to solve, I don't have any more time to volunteer to your project. best wishes!!

@jquast jquast closed this Mar 4, 2026
@astanin
Copy link
Owner

astanin commented Mar 4, 2026

OK, thanks!

@jquast jquast deleted the jq/wcwidth-030-integration branch March 4, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

incomplete This PR requires some further changes or modifications before it can be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants