Cross platform colored output in Python.
Using pyspectrum is really simple. After installing, try the following script:
import pyspectrum
pyspectrum.cyan('Hello, World!')
The program should output some colored text.
You can change background colors too (have a look in pyspectrum/color.py
for a full list of foreground and background colors):
from pyspectrum import color
from pyspectrum import output
colored_output = output.ColoredOutput(color.FG_WHITE, color.BG_RED)
colored_output.print('White text on a blue background!')
In the above example, the print
method behaves almost exactly to the inbuilt equivalent. A printf
function has also been implemented (why not). Extending the above example:
colored_output.printf('4 * 2 = %d\n', 8)
Note that ColoredOutput.printf
behaves very similarly to the printf
that can be found in stdio.h
of the C Programming Language. If you want a line feed at the end of your format string, you have to include it yourself.
Pyspectrum requires Python 3. There are no other dependencies!
Your terminal/console must be capable of interpreting ANSI escape sequences. Linux distributions (and the Windows Subsystem for Linux) come with these capabilities by default. The Windows 10 command prompt does as well - but not by default. This is not a problem though as pyspectrum/output.py
turns such features on programmatically for the duration of program runtime only.
If you haven't read the requirements section, I would recommend that you do so now.
This project has not yet been uploaded to the Python Package Index, so this feature is currently not available. I will be sure to post instructions here when it is!
- Clone the repository
git clone https://github.com/maxgodfrey2004/pyspectrum
-
Navigate to the repo's root directory
-
(Optional) Install pyspectrum locally (use either of the following)
pip3 install -e .
python3 -m pip3 install -e .