Python script to format and print text with fun colours
Enter rainbow
string to formant string and print the result to the console (standard output). Use rainbow --file
file to format the contents of the text file file and print the results. By default, the text is split by character; specify -w
to instead have the formatting applied on a word by word basis. For a detailed description of the available formatting, see rainbow --help
.
- Ensure
rainbow.py
and `usage' are in the same directory - Edit the
SCRIPT_DIR
variable at the top of theRainbow()
class inrainbow.py
- Create an alias, for example in
~/.bashrc
alias rainbow="python full_path_to_rainbow.py"
(Otherwise python full_path_to_rainbow.py
will be required to invoke the script).
Here python
should refer to your python3 executable (python3
on some systems).
Apply formatting to the standard output of bash commands using command substitution. For example,
rainbow "$(ls)" -bg
rainbow "$(cal)" -fg -b
(note that double quotes, not single quotes, must be used here).
Have some fun with the available formatting. A personal favourite is the simple combination -w -fg
.
- Hidden character formatting
- 256 colour formatting
- Finer control over formatting (e.g. every 1 in 3 characters blinking)
- If
-dec
is used in conjunction with-b
, the frequency of occurrence of blinking characters or words is reduced.
Tested in the rxvt-unicode
terminal emulator running bash.
- Added
-a
and-w
options - Fixed handling of
-nfw
and-bf
options when used in conjunction with each other and-fg
,-bg
- Fixed error when an empty string is passed as an arguement