Support for RGB hexadecimal triplets colors notations
This commit is contained in:
parent
9b3e8e257c
commit
8832a41afe
2 changed files with 21 additions and 4 deletions
11
README.md
11
README.md
|
|
@ -20,7 +20,8 @@ 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,
|
Available colors are: blue, black, yellow, cyan, green, magenta, white, red,
|
||||||
rainbow, random, Random, scale, none or any number between 0 and 255.
|
rainbow, random, Random, scale, none, an RGB hexadecimal triplet 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 or random (some styles may have no effect, depending
|
rapid_blink, reverse, conceal or random (some styles may have no effect, depending
|
||||||
|
|
@ -38,9 +39,11 @@ below, [0-100] by default).
|
||||||
If the python-pygments library is installed, you can use the name of a
|
If the python-pygments library is installed, you can use the name of a
|
||||||
syntax-coloring "lexer" as a color (for example: "Cpp", "ruby", "xml+django", etc.).
|
syntax-coloring "lexer" as a color (for example: "Cpp", "ruby", "xml+django", etc.).
|
||||||
|
|
||||||
If GIMP palettes files (*.gpl) are available, you can also use their names
|
If GIMP palettes files (*.gpl) are available, you can also use their names as a
|
||||||
as a colormap. Note that the RGB colors will be converted to their nearest ANSI
|
colormap (see the `-P` switch below).
|
||||||
256-colors mode equivalents (see the `-P` switch below).
|
|
||||||
|
Note that the RGB colors (either the hex triplets or the palettes's colors) will
|
||||||
|
be converted to their nearest ANSI 256-colors mode equivalents.
|
||||||
|
|
||||||
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_.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,13 @@ def rgb_to_ansi( red, green, blue ):
|
||||||
return int(val)
|
return int(val)
|
||||||
|
|
||||||
|
|
||||||
|
def hex_to_rgb(h):
|
||||||
|
assert( h[0] == "#" )
|
||||||
|
h = h.lstrip('#')
|
||||||
|
lh = len(h)
|
||||||
|
return tuple( int(h[i:i+lh//3], 16) for i in range(0, lh, lh//3) )
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Global variables
|
# Global variables
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
@ -339,6 +346,13 @@ def colorin(text, color="red", style="normal"):
|
||||||
mode = 8
|
mode = 8
|
||||||
color_code = str(30 + colors[color])
|
color_code = str(30 + colors[color])
|
||||||
|
|
||||||
|
# hexadecimal color
|
||||||
|
elif color[0] == "#":
|
||||||
|
mode = 256
|
||||||
|
color_nb = rgb_to_ansi(*hex_to_rgb(color))
|
||||||
|
assert(0 <= color_nb <= 255)
|
||||||
|
color_code = str(color_nb)
|
||||||
|
|
||||||
# 256 colors mode
|
# 256 colors mode
|
||||||
elif color.isdigit():
|
elif color.isdigit():
|
||||||
mode = 256
|
mode = 256
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue