Skip to main content
Build Status Coverage Status Documentation Status GitHub Release Status PyPI Release Status PyPI Supported Python Versions License Status

ansiwrap wraps text, like the standard textwrap module. But it also correctly wraps text that contains ANSI control sequences that colorize or style text.

Where textwrap is fooled by the raw string length of those control codes, ansiwrap is not; it understands that however much those codes affect color and display style, they have no logical length.

The API mirrors the wrap, fill, and shorten functions of textwrap. For example:

from __future__ import print_function
from colors import *     # ansicolors on PyPI
from ansiwrap import *

s = ' '.join([red('this string'),
              blue('is going on a bit long'),
              green('and may need to be'),
              color('shortened a bit', fg='purple')])

print('-- original string --')
print(s)
print('-- now filled --')
print(fill(s, 20))
print('-- now shortened / truncated --')
print(shorten(s, 20, placeholder='...'))

It also exports several other functions:

  • ansilen (giving the effective length of a string, ignoring ANSI control codes)

  • ansi_terminate_lines (propagates control codes though a list of strings/lines and terminates each line.)

  • strip_color (removes ANSI control codes from a string)

See also the enclosed demo.py.

https://github.com/doblabs/ansiwrap-hotoffthehamster/blob/release/docs/assets/00000569.png

Metadata

Release files for ansiwrap-hotoffthehamster 0.8.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansiwrap-hotoffthehamster 0.8.7
File Size Uploaded Provenance
ansiwrap_hotoffthehamster-0.8.7.tar.gz 31.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ansiwrap-hotoffthehamster 0.8.7
File Interpreter ABI Platform
ansiwrap_hotoffthehamster-0.8.7-py3-none-any.whl Python 3 none any Details

Total release size: 39.6 kB

Release files / ansiwrap_hotoffthehamster-0.8.7.tar.gz

Download URL ansiwrap_hotoffthehamster-0.8.7.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
caaf939682b9ba306c7a7c80dbf31ff9f2e460a0943c6899fc70660766447aa1
BLAKE2b-256 checksum
How to use checksums
c43dcd19ac1313ccaf2cfe2fb8f9f6c09de12cc8b0d1a8a4badc4591929ad51c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / ansiwrap_hotoffthehamster-0.8.7-py3-none-any.whl

Download URL ansiwrap_hotoffthehamster-0.8.7-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
adcfa28d63393b2d50fb1186bfd3587cb8a6caf2a0039a115acecec71486c101
BLAKE2b-256 checksum
How to use checksums
0007abd70163c49fe61e1991d24cd0c8c367769a42c27a81bc5168d24b1037f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Security for ansiwrap-hotoffthehamster 0.8.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page