Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/msabramo/ansi_str

Experiment with Python str subclass whose __len__ excludes ANSI escapes
https://github.com/msabramo/ansi_str

Last synced: about 1 month ago
JSON representation

Experiment with Python str subclass whose __len__ excludes ANSI escapes

Awesome Lists containing this project

README

        

ansi_str
========

You should just use https://github.com/Robpol86/colorclass
----------------------------------------------------------

An experimental Python ``str`` subclass, whose ``__len__`` method excludes ANSI
color escape codes

When you call the ``__len__`` method, it discounts ANSI color escape codes.
This is beneficial, because ANSI color escape codes won't mess up code that
tries to do alignment, padding, printing in columns/tables, etc.

.. image:: ansi_str_example.png

.. code-block:: python

In [1]: from ansi_str import ansi_str

In [2]: s = ansi_str(u'\x1b[32m\x1b[1mSUCCESS\x1b[0m')

In [3]: len(s)
Out[3]: 7