ansiwrap


Nameansiwrap JSON
Version 0.8.4 PyPI version JSON
download
home_pagehttps://github.com/jonathaneunice/ansiwrap
Summarytextwrap, but savvy to ANSI colors and styles
upload_time2019-01-23 22:17:06
maintainer
docs_urlNone
authorJonathan Eunice
requires_python
licenseApache License 2.0
keywords text textwrap ansi colors
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            
| |travisci| |version| |versions| |impls| |wheel| |coverage|

.. |travisci| image:: https://api.travis-ci.org/jonathaneunice/ansiwrap.svg
    :target: http://travis-ci.org/jonathaneunice/ansiwrap

.. |version| image:: http://img.shields.io/pypi/v/ansiwrap.svg?style=flat
    :alt: PyPI Package latest release
    :target: https://pypi.python.org/pypi/ansiwrap

.. |versions| image:: https://img.shields.io/pypi/pyversions/ansiwrap.svg
    :alt: Supported versions
    :target: https://pypi.python.org/pypi/ansiwrap

.. |impls| image:: https://img.shields.io/pypi/implementation/ansiwrap.svg
    :alt: Supported implementations
    :target: https://pypi.python.org/pypi/ansiwrap

.. |wheel| image:: https://img.shields.io/pypi/wheel/ansiwrap.svg
    :alt: Wheel packaging support
    :target: https://pypi.python.org/pypi/ansiwrap

.. |coverage| image:: https://img.shields.io/badge/test_coverage-99%25-0000FF.svg
    :alt: Test line coverage
    :target: https://pypi.python.org/pypi/ansiwrap


``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``.

.. image:: https://content.screencast.com/users/jonathaneunice/folders/Jing/media/8db64be2-01cc-4da4-b46a-789c53c63b44/00000569.png
   :align: center

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jonathaneunice/ansiwrap",
    "name": "ansiwrap",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "text textwrap ANSI colors",
    "author": "Jonathan Eunice",
    "author_email": "jonathan.eunice@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7c/45/2616341cfcace37d4619d5106a85fcc24f2170d1a161bc5f7fdb81772fbc/ansiwrap-0.8.4.zip",
    "platform": "",
    "description": "\n| |travisci| |version| |versions| |impls| |wheel| |coverage|\n\n.. |travisci| image:: https://api.travis-ci.org/jonathaneunice/ansiwrap.svg\n    :target: http://travis-ci.org/jonathaneunice/ansiwrap\n\n.. |version| image:: http://img.shields.io/pypi/v/ansiwrap.svg?style=flat\n    :alt: PyPI Package latest release\n    :target: https://pypi.python.org/pypi/ansiwrap\n\n.. |versions| image:: https://img.shields.io/pypi/pyversions/ansiwrap.svg\n    :alt: Supported versions\n    :target: https://pypi.python.org/pypi/ansiwrap\n\n.. |impls| image:: https://img.shields.io/pypi/implementation/ansiwrap.svg\n    :alt: Supported implementations\n    :target: https://pypi.python.org/pypi/ansiwrap\n\n.. |wheel| image:: https://img.shields.io/pypi/wheel/ansiwrap.svg\n    :alt: Wheel packaging support\n    :target: https://pypi.python.org/pypi/ansiwrap\n\n.. |coverage| image:: https://img.shields.io/badge/test_coverage-99%25-0000FF.svg\n    :alt: Test line coverage\n    :target: https://pypi.python.org/pypi/ansiwrap\n\n\n``ansiwrap`` wraps text, like the standard ``textwrap`` module.\nBut it also correctly wraps text that contains ANSI control\nsequences that colorize or style text.\n\nWhere ``textwrap`` is fooled by the raw string length of those control codes,\n``ansiwrap`` is not; it understands that however much those codes affect color\nand display style, they have no logical length.\n\nThe API mirrors the ``wrap``, ``fill``, and ``shorten``\nfunctions of ``textwrap``. For example::\n\n    from __future__ import print_function\n    from colors import *     # ansicolors on PyPI\n    from ansiwrap import *\n\n    s = ' '.join([red('this string'),\n                  blue('is going on a bit long'),\n                  green('and may need to be'),\n                  color('shortened a bit', fg='purple')])\n\n    print('-- original string --')\n    print(s)\n    print('-- now filled --')\n    print(fill(s, 20))\n    print('-- now shortened / truncated --')\n    print(shorten(s, 20, placeholder='...'))\n\nIt also exports several other functions:\n\n* ``ansilen`` (giving the effective length of a string, ignoring ANSI control codes)\n* ``ansi_terminate_lines`` (propagates control codes though a list of strings/lines\n  and terminates each line.)\n* ``strip_color`` (removes ANSI control codes from a string)\n\nSee also the enclosed ``demo.py``.\n\n.. image:: https://content.screencast.com/users/jonathaneunice/folders/Jing/media/8db64be2-01cc-4da4-b46a-789c53c63b44/00000569.png\n   :align: center\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "textwrap, but savvy to ANSI colors and styles",
    "version": "0.8.4",
    "split_keywords": [
        "text",
        "textwrap",
        "ansi",
        "colors"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "3b2aabe86f0810057147c2f7f5deb1db",
                "sha256": "7b053567c88e1ad9eed030d3ac41b722125e4c1271c8a99ade797faff1f49fb1"
            },
            "downloads": -1,
            "filename": "ansiwrap-0.8.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3b2aabe86f0810057147c2f7f5deb1db",
            "packagetype": "bdist_wheel",
            "python_version": "3.6",
            "requires_python": null,
            "size": 8533,
            "upload_time": "2019-01-23T22:17:10",
            "upload_time_iso_8601": "2019-01-23T22:17:10.095499Z",
            "url": "https://files.pythonhosted.org/packages/03/50/43e775a63e0d632d9be3b3fa1c9b2cbaf3b7870d203655710a3426f47c26/ansiwrap-0.8.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "0e24741bda593b7bd2162c3e3bd3b8ba",
                "sha256": "ca0c740734cde59bf919f8ff2c386f74f9a369818cdc60efe94893d01ea8d9b7"
            },
            "downloads": -1,
            "filename": "ansiwrap-0.8.4.zip",
            "has_sig": false,
            "md5_digest": "0e24741bda593b7bd2162c3e3bd3b8ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 17666,
            "upload_time": "2019-01-23T22:17:06",
            "upload_time_iso_8601": "2019-01-23T22:17:06.512958Z",
            "url": "https://files.pythonhosted.org/packages/7c/45/2616341cfcace37d4619d5106a85fcc24f2170d1a161bc5f7fdb81772fbc/ansiwrap-0.8.4.zip",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-01-23 22:17:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "jonathaneunice",
    "github_project": "ansiwrap",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "ansiwrap"
}
        
Elapsed time: 0.01119s