Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyansi

Minimal, dependency-free ANSI color helper for terminal CLIs. A single drop-in .py file, meant to be copied wherever it's needed rather than installed as a package.

Usage

from pyansi import Ansi

ansi = Ansi()                   # defaults to stream=sys.stdout
print(ansi.red("error"))
print(ansi.red.bold("error"))   # order doesn't matter
print(ansi.bold.red("error"))   # same output as above

Colors: black, red, green, yellow, blue, magenta, cyan, white, orange. Every color chains with .bold in either order. Color is automatically disabled when output isn't a tty, or when NO_COLOR is set (no-color.org).

There's no reset() -- every call returns a complete, self-contained string (codes already opened and closed), so it composes with normal print()/f-strings instead of imposing its own output model.

Run the file directly for a demo of every color:

./pyansi.py

Install

Copy pyansi.py wherever your script can import it. If it's alongside your script, a plain from pyansi import Ansi works as-is.

To install it somewhere shared (e.g. /usr/local/include, for other scripts to import from), run:

./install.sh

This copies pyansi.py to /usr/local/include/pyansi.py (needs sudo). Scripts importing it from there need to add that directory to sys.path first -- see the import example in pyansi.py's own docstring.

Testing

pip install pytest
pytest

License

MIT -- see LICENSE.

About

Minimal, dependency-free ANSI color helper for terminal CLIs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages