Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-142035: Textwrap without ansi escapes#142040

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
alexprengere wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromalexprengere:textwrap_without_ansi_escapes

Conversation

@alexprengere
Copy link
Contributor

@alexprengerealexprengere commentedNov 28, 2025
edited by bedevere-appbot
Loading

@alexprengerealexprengereforce-pushed thetextwrap_without_ansi_escapes branch from21b7359 to6517434CompareNovember 28, 2025 14:46
@alexprengere
Copy link
ContributorAuthor

alexprengere commentedNov 28, 2025
edited
Loading

This is just a POC, it needs tests, docs, etc.
Note that there are other issues with unicode handling, textwrap will split multiple-code-points glyphs.

>>>textwrap.wrap("Cafe\u0301 is good",width=4)['Cafe','́ is','good']

@picnixz
Copy link
Member

picnixz commentedNov 29, 2025
edited
Loading

Sorry but we should not changetextwrap now. It's a major change and this may break more than one code (it's also a new feature so we cannot fix 3.14 directly). I've had this kind of issue with Sphinx recently:sphinx-doc/sphinx#13762 where 0-width glyphs are not handled correctly by textwrap. I will close this PR and suggest that you first focus on fixing argparse itself for the colors if you want.

@picnixz
Copy link
Member

picnixz commentedNov 29, 2025
edited
Loading

Oh actually the patch is quite simple. However as it's a new feature we cannot backport it =/ so we need to think of a solution that can be backported. If it's not possible I would suggest:

  • Leaving it like this in 3.14.
  • Fix it in 3.15 with the new feature you suggested.

If the PR is not ready, I will make it a draft.

@picnixzpicnixz reopened thisNov 29, 2025
@picnixzpicnixz marked this pull request as ready for reviewNovember 29, 2025 09:18
@picnixzpicnixz marked this pull request as draftNovember 29, 2025 09:18
@alexprengere
Copy link
ContributorAuthor

Thanks for the reply! I was not thinking about backporting the changes to 3.14 to be honest.

The cleanest solution would be to incorporate a complete unicode handling with a technique similar towcwidth, that would allow for proper wrapping of all glyphs.

That being said, as this would be indeed a major addition to stdlib, a good first step might be to add the new option toignore_ansi_escape totextwrap, as this is a much smaller change, and backward-compatible as well, if it defaults toFalse. My initial PR was a draft already, but I can finish it if you feel this is OK.

@picnixz
Copy link
Member

Well.. looks like the current tests are broken which is not good. I need to think about the changes totextwrap. Ideally, we should be able to specify alen function instead. That's what I did when I wrote my Sphinx' fix. We have a custom_wrap_text. But OTOH, I think we should do something intextwrap to make it extensible or subclassable so that the logic of detecting a word & length is actually overridable. For now, let's hold a bit so that you are not working for naught.

@serhiy-storchaka Do you think it makes sense to maketextwrap more customizable in how it detects the different words and splits. We can already do it through a regex but we should also be able to provide a custom length function to have a better tweakable behavior. This is just an idea and this really needs more polishing especially with how we would like to provide such interface if this makes sense.

@alexprengere
Copy link
ContributorAuthor

Sorry, the draft contained a bug due to a copy paste error, I just pushed a fix.

@serhiy-storchaka
Copy link
Member

See#56708, and also#56777 and#68853. I think that they would also resolve this issue.

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

Reviewers

@savannahostrowskisavannahostrowskiAwaiting requested review from savannahostrowskisavannahostrowski is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@alexprengere@picnixz@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp