ANSIColors (version 1.8b, ven. 15/02/2013 at 00h:22m:31s) | index ANSIColors.py ANSIColors.py.html |
An efficient and simple ANSI colors module (and also a powerfull script), with functions to print text using colors.
About the convention for the names of the colors :
* for the eight colors black, red, green, yellow, blue, magenta, cyan, white:
* the name in minuscule is for color **with bold** (example 'yellow'),
* the name starting with 'B' is for color **without bold** (example 'Byellow'),
* the name starting with a capital letter is for the backgroung color (example 'Yellow').
* for the special effects (blink, italic, bold, underline, negative), **not always supported** :
* the name in minuscule is for **activate** the effect,
* the name starting in capital letter is for **desactivate** the effect.
* for the other special effects (nocolors, default, Default, clear, el), the effect is **immediate** (and seems to be well supported).
List of functions:
==================
To print a string
-----------------
* sprint: give a string,
* printc: like __builtin__.print, but with interpreting balises to put colors,
* writec: like printc, but using any file object (and no new line added at the end of the string),
To clean the terminal or the line
---------------------------------
* erase: erase all ANSI colors balises in the string (like sprint, but erasing and not interpreting color balises)
* clearLine, clearScreen: to clear the current line or screen,
* Reset: to return to default foregroung and backgroung, and stopping all *fancy* effects (like blinking or reverse video).
Others functions
----------------
* notify: try to display a *system* notification. **Only on *linux*.**
* xtitle: try to set the *title* of the terminal. **Not always supported**.
Example of use (module) :
=========================
To store a string, use *sprint* (*i.e.* print to a string, sprint), like here ::
>>> example=sprint("France flag is <blue>blue<white>white<red>red<white>, Iran flag if <green>green only<white>.")
The string *example* can then be printed, with colors, with ::
>>> print example # Sorry, but in the documentation it is hard to show colors :)
France flag is bluewhitered, Iran flag if green only.
To directly print a string colored by balises, use *printc* ::
>>> printc("Batman's costum is <black>black<white>, Aquaman's costum is <blue>blue<white> and <green>green<white>.")
.. seealso::
This is the most usefull function. To do the same, but on any file, use *writec*
Moreover, the function *erase* can also be usefull to simply delete all *valid* color balises ::
>>> print erase("Batman's costum is <black>black<white>, Aquaman's costum is <blue>blue<white> and <green>green<white>, and this is a non-valid <balise>, so it is kept like this.")
Batman's costum is black, Aquaman's costum is blue and green, and this is a non-valid <balise>, so it is kept like this
In this last example, *<el>* balise is used to erase the current content of the line, usefull to make a *dynamical* print ::
>>> writec("<red>Computing <u>2**(2**(2**4))<reset>...."); tmp=2**(2**(2**4)); writec("<el><green> Done !<reset>")
Done !
The first 'Computing 2**(2**(2**4))....' have disappeared after the computation !
Example of use (script):
========================
* To show the help ::
$ ANSIColors.py --help
* To run a test ::
$ ANSIColors.py --test
* To produce a GNU Bash color aliases file ::
$ ANSIColors.py --generate --file ~/.color_aliases.sh
About:
======
Now, this script can detect if ANSI codes are supported :
1. *$ ANSIColors.py --help* : will print with colors if colors seems to be supported;
2. *$ ANSIColors.py --help --noANSI* : will print without any colors, even if it is possible;
3. *$ ANSIColors.py --help --ANSI* : will print without colors, even they seems to be not supported.
And, the module part behave identically.
This module is concluded.
The reference page for ANSI code is : `here on Wikipedia <http://en.wikipedia.org/wiki/ANSI_escape_code>`_.
The reference page for XTitle escape code is : `here <http://www.faqs.org/docs/Linux-mini/Xterm-Title.html>`_.
Copyrigths:
===========
(c) October 2012 - February 2013
By Lilian BESSON,
ENS de Cachan (M1 Mathematics & M1 Computer Science MPRI)
mailto:lbesson[AT]ens-cachan.fr
For Naereen Corp.
mailto:naereen-corporation[AT]laposte.net
https:sites.google.com/site/naereencorp
Modules | ||||||
|
Functions | ||
|
Data | ||
ANSISupported = False B = '' Bblack = '' Bblue = '' Bcyan = '' Bgreen = '' Black = '' Blink = '' Blue = '' Bmagenta = '' Bred = '' Bwhite = '' Byellow = '' Cyan = '' Default = '' ERROR = '' Green = '' INFO = '' Italic = '' Magenta = '' Neg = '' Red = '' U = '' WARNING = '' White = '' Yellow = '' __author__ = 'Lilian BESSON (mailto:lilian.besson[AT]normale.fr)' __date__ = 'ven. 15/02/2013 at 00h:22m:31s' __version__ = '1.8b' b = '' bell = '' black = '' blink = '' blue = '' clear = '' colorList = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'Bblack', 'Bred', 'Bgreen', 'Byellow', 'Bblue', 'Bmagenta', 'Bcyan', 'Bwhite', 'Black', 'Red', 'Green', 'Yellow', ...] cyan = '' default = '' el = '' green = '' italic = '' magenta = '' n = 'INFO' neg = '' nocolors = '' question = '' red = '' reset = '' simpleColorList = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'] title = '' u = '' warning = '' white = '' yellow = '' |
Author | ||
Lilian BESSON (mailto:lilian.besson[AT]normale.fr) |