Add random and rainbow
Use "random" as a color or a style to pick a random one for each pattern. Use "rainbow" as a color to alternate colors in rainbow gradient. Fix #1
This commit is contained in:
parent
941d7c2ef9
commit
119bba5bb5
2 changed files with 38 additions and 12 deletions
|
|
@ -19,11 +19,11 @@ with commas. If you indicate more colors than groups, the last ones will be igno
|
||||||
If you ask for less colors, the last one will be duplicated across remaining
|
If you ask for less colors, the last one will be duplicated across remaining
|
||||||
groups.
|
groups.
|
||||||
|
|
||||||
Available colors are: blue, black, yellow, cyan, green, magenta, white, red or
|
Available colors are: blue, black, yellow, cyan, green, magenta, white, red,
|
||||||
any number between 0 and 255.
|
rainbow, random, or any number between 0 and 255.
|
||||||
|
|
||||||
Available styles are: normal, bold, faint, italic, underline, blink,
|
Available styles are: normal, bold, faint, italic, underline, blink,
|
||||||
rapid_blink, reverse, conceal.
|
rapid_blink, reverse, conceal or random.
|
||||||
|
|
||||||
When not specified, a *COLOR* defaults to _red_ and a *STYLE* defaults to _bold_.
|
When not specified, a *COLOR* defaults to _red_ and a *STYLE* defaults to _bold_.
|
||||||
|
|
||||||
|
|
@ -56,6 +56,9 @@ special characters that would be recognize by your shell.
|
||||||
* Color in bold violet home directories in _/etc/passwd_:
|
* Color in bold violet home directories in _/etc/passwd_:
|
||||||
`colout /home/[a-z]+ 135 < /etc/passwd`
|
`colout /home/[a-z]+ 135 < /etc/passwd`
|
||||||
|
|
||||||
|
* Use a different color for each line of the auth log
|
||||||
|
`grep user /var/log/auth.log | colout "^.*$" rainbow`
|
||||||
|
|
||||||
* Color in yellow user/groups id, in bold green name and in bold red home directories in _/etc/passwd_:
|
* Color in yellow user/groups id, in bold green name and in bold red home directories in _/etc/passwd_:
|
||||||
`colout :x:\([0-9]+:[0-9]+\):\([a-z]+\).*\(/home/[a-z]+\) yellow,green,red normal,bold < /etc/passwd`
|
`colout :x:\([0-9]+:[0-9]+\):\([a-z]+\).*\(/home/[a-z]+\) yellow,green,red normal,bold < /etc/passwd`
|
||||||
|
|
||||||
|
|
|
||||||
29
colout.py
Normal file → Executable file
29
colout.py
Normal file → Executable file
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
# Color Up Arbitrary Command Ouput
|
# Color Up Arbitrary Command Ouput
|
||||||
# Licensed under the GPL version 3
|
# Licensed under the GPL version 3
|
||||||
# 2012 (c) nojhan <nojhan@gmail.com>
|
# 2012 (c) nojhan <nojhan@nojhan.net>
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import random
|
||||||
|
|
||||||
###########
|
###########
|
||||||
# Library #
|
# Library #
|
||||||
|
|
@ -25,6 +25,9 @@ colors = {
|
||||||
"magenta":5, "cyan":6, "white":7
|
"magenta":5, "cyan":6, "white":7
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rainbow = [ "red", "yellow", "green", "cyan", "blue", "magenta" ]
|
||||||
|
rainbow_idx = 0
|
||||||
|
|
||||||
# Escaped end markers for given color modes
|
# Escaped end markers for given color modes
|
||||||
endmarks = {8:";", 256:";38;5;"}
|
endmarks = {8:";", 256:";38;5;"}
|
||||||
|
|
||||||
|
|
@ -47,11 +50,31 @@ def colorin( text, color = "red", style = "normal" ):
|
||||||
stop = "\033[0m"
|
stop = "\033[0m"
|
||||||
|
|
||||||
# Convert the style code
|
# Convert the style code
|
||||||
|
if style == "random":
|
||||||
|
style = random.choice(list(styles.keys()))
|
||||||
|
else:
|
||||||
assert( style in styles)
|
assert( style in styles)
|
||||||
|
|
||||||
style_code = str(styles[style])
|
style_code = str(styles[style])
|
||||||
|
|
||||||
|
if color == "random":
|
||||||
|
mode = 8
|
||||||
|
color_code = random.choice(list(colors.values()))
|
||||||
|
color_code = str( 30 + color_code )
|
||||||
|
|
||||||
|
elif color == "rainbow":
|
||||||
|
global rainbow_idx
|
||||||
|
mode = 8
|
||||||
|
color = rainbow[rainbow_idx]
|
||||||
|
color_code = str( 30 + colors[color] )
|
||||||
|
|
||||||
|
if rainbow_idx < len(rainbow)-1:
|
||||||
|
rainbow_idx += 1
|
||||||
|
else:
|
||||||
|
rainbow_idx = 0
|
||||||
|
|
||||||
# 8 colors modes
|
# 8 colors modes
|
||||||
if color in colors:
|
elif color in colors:
|
||||||
mode = 8
|
mode = 8
|
||||||
color_code = str( 30 + colors[color] )
|
color_code = str( 30 + colors[color] )
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue