gh-142035: Make TextWrapper ANSI-aware#152702
Open
kdeldycke wants to merge 1 commit into
Open
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
This was referenced Jun 30, 2026
kdeldycke
added a commit
to kdeldycke/cpython
that referenced
this pull request
Jun 30, 2026
21c6877 to
4497db3
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
kdeldycke
added a commit
to kdeldycke/cpython
that referenced
this pull request
Jun 30, 2026
4497db3 to
baba0c5
Compare
This was referenced Jun 30, 2026
kdeldycke
added a commit
to kdeldycke/cpython
that referenced
this pull request
Jun 30, 2026
# Conflicts: # Doc/whatsnew/3.16.rst
baba0c5 to
36a27ac
Compare
kdeldycke
added a commit
to kdeldycke/cpython
that referenced
this pull request
Jun 30, 2026
36a27ac to
ac1a642
Compare
ac1a642 to
090c887
Compare
TextWrapper ANSI-awareTextWrapper ANSI-aware
Documentation build overview
|
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.
Description
Add a text_len parameter to
textwrap.wrap,textwrap.fill,textwrap.shortenandtextwrap.TextWrapper. It customizes how the visible width of a string is measured, so text that contains zero-width or double-width characters, or invisible ANSI escape sequences, can be wrapped correctly.Context
I am a maintainer of Click and had to maintain my own local fork of
TextWrapperto make it strip ANSI strings properly. See my initial code at: pallets/click#3420 . This PR is a direct port of that code to Python standard library.This PR: