Skip to main content

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>').

Other tags

The following tags are also available :

  • italic, Italic : to turn on and off the italic mode (not always supported),
  • b, B : to turn on and off the bold mode (not always supported),
  • u, U : to turn on and off the underline mode (not always supported),
  • neg, Neg : to turn on and off the reverse video mode,
  • blink, Blink : to turn on and off the blink mode (not always supported),
  • el : to erase the current line,
  • bell : to make the terminal’s bell ring (not always supported).

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

This version
History Node

1.9.9.public

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
ANSIColors-balises-1.9.9.public.tar.gz (14.2 kB) Copy SHA256 hash SHA256 Source None Mar 20, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page