FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-154686: Add `text_len` to `TextWrapper` by kdeldycke · Pull Request #152702 · python/cpython · GitHub

Repository navigation

gh-154686: Add text_len to TextWrapper - #152702

Open
kdeldycke wants to merge 1 commit into
python:mainfrom
kdeldycke:ANSI-aware-TextWrapper
Open

kdeldycke wants to merge 1 commit into
python:mainfrom
kdeldycke:ANSI-aware-TextWrapper

Conversation

kdeldycke commented Jun 30, 2026 •
edited
Loading

Copy link
Copy Markdown

Description

Add a text_len parameter to textwrap.wrap, textwrap.fill, textwrap.shorten and textwrap.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.

This has the side effect of removing the local patch in _split_lines introduced by #154634 .

Context

I am a maintainer of Click and had to maintain my own local fork of TextWrapper to 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:

bedevere-app Bot commented Jun 30, 2026

Copy link
Copy Markdown

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 skip news label instead.

python-cla-bot Bot commented Jun 30, 2026 •
edited
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

bedevere-app Bot commented Jun 30, 2026

Copy link
Copy Markdown

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 skip news label instead.

kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jun 30, 2026
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 4497db3 to baba0c5 Compare June 30, 2026 15:40
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jun 30, 2026
# Conflicts:
#	Doc/whatsnew/3.16.rst
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from baba0c5 to 36a27ac Compare June 30, 2026 16:06
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jun 30, 2026
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 36a27ac to ac1a642 Compare June 30, 2026 16:07
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jun 30, 2026
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from ac1a642 to 090c887 Compare June 30, 2026 16:10
kdeldycke changed the title gh142035: Make TextWrapper ANSI-aware gh-142035: Make TextWrapper ANSI-aware Jun 30, 2026

read-the-docs-community Bot commented Jun 30, 2026 •
edited
Loading

Copy link
Copy Markdown

Comment thread Doc/library/textwrap.rst Outdated
Comment thread Lib/test/test_textwrap.py
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jul 15, 2026
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 8327c94 to ba63d75 Compare July 15, 2026 23:34
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jul 15, 2026
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 219db60 to 8e3c15a Compare July 15, 2026 23:45
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jul 25, 2026
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 8e3c15a to 3cdc69f Compare July 25, 2026 09:49
kdeldycke changed the title gh-142035: Make TextWrapper ANSI-aware gh-154686: Make TextWrapper ANSI-aware Jul 25, 2026
kdeldycke changed the title gh-154686: Make TextWrapper ANSI-aware gh-154686: Add text_len to TextWrapper Jul 25, 2026
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jul 25, 2026
For ANSI and variable character width awareness.

Removes local patch introduced in python#154634.
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 3cdc69f to 847d242 Compare July 25, 2026 10:19
kdeldycke added a commit to kdeldycke/cpython that referenced this pull request Jul 25, 2026
For ANSI and variable character width awareness.

Removes local patch introduced in python#154634.
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 847d242 to 1497de0 Compare July 25, 2026 11:47
For ANSI and variable character width awareness.

Removes local patch introduced in python#154634.
kdeldycke force-pushed the ANSI-aware-TextWrapper branch from 4f1e56d to 27b653d Compare July 31, 2026 16:48
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add text_len to TextWrapper for ANSI and variable character width awareness textwrap.wrap: add control for fonts with different character widths

2 participants


Back | FazBrowse Home | New Git URL