ANSIColors brings a simple and powerful way to use colours in a terminal.
Project description
About
Provide efficient and useful functions to use colors, in a HTML-tag style.
Almost all ANSI Colors are defined with this tags-like style. This point is the main interest of this module, because many others define functions to print with some colors.
The reset tag is a special one to reinitialize all previously changed parameters.
Colors
Foregrounds
You can choose one of the 8 basic ANSI colors: black, red, green, yellow, blue, magenta, cyan, white. The names beginning with a lower-script design foreground colors.
For example
ANSIColors.printc('<reset>this is default. <red>this is red<yellow> and yellow in foreground now<reset>').
Backgrounds
You can choose one of the 8 basic ANSI colours: Black, Red, Green, Yellow, Blue, Magenta, Cyan, White. The names beginning with a upper-script design background colors.
For example
ANSIColors.printc('<Default>this is default. <Blue>this have a blue background<Black> and black in background now<reset>').
Macros
Some macros are also provided, like the tags <ERROR>, <INFO> or <WARNING>.
And also <warning> and <question>, which respectively gives a colored ! and ?.
Writing to a file
This is possible with the writec function. For example
import sys ANSIColors.writec('<ERROR><u><red>The computer is going to explode!<reset>', fn=sys.stderr) # sys.stderr.flush() # this is useless : writec flush itself.
Auto detection
Of course, the colors are disabled if the output doesn’t support them (e.g. a file or a piped command).
It works perfectly on GNU/Linux (tested on Ubuntu, Arch-Linux, Debian, Fedora and Angstrom) and Windows (with OR without Cygwin), and have not be tested on MAC OS X (but it should be alright).
Other features
Others functions
This module provides also the xtitle function, to change the title of the terminal. It tries to use the command xtitle, and if not available, tries to use one ANSI Code to change the title.
This module provides a notify function to display a system notification (using notify-send on Debian-like, not working on Windows).
Script
ANSIColors.py is also a script. You can have his description (or use it) directly with
python -m ANSIColors --help
For testing
It can be used to run some tests (with the –test option).
With GNU/Bash
It can be used to generate a GNU/Bash color profile (with the --generate --file color.sh options).
This sh file can be imported with $ . color.sh in any GNU/Bash scripts, or even in your ~/.bashrc file.
An up-to-date version of this complete color profile can be found on my webpage.
License
This module is licensed under the term of the GNU Public License, version 3 (GPLv3). See the file LICENSE for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ANSIColors-balises-1.9.9.public.tar.gz
.
File metadata
- Download URL: ANSIColors-balises-1.9.9.public.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df8b3449d7e1b71d9935b0e1d6e8cad25864c6c3abb8dad15648bacd0bf49a3f |
|
MD5 | 12f61ce4f2f1632785de247a66e01d4b |
|
BLAKE2b-256 | d69ef4a7cfb728d0648a3d8cb25a581bfbecfb372f0fff6cf31b16f4b21af693 |