From 56f9f0d7e6f810b7edbcb8ed934004f289696aa4 Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 25 Apr 2014 14:28:15 +0200 Subject: [PATCH] bugfix: random in 8-colors mode with user-defined default colormap --- README.md | 22 +++++++++++----------- colout/colout.py | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c49e5db..f13ae26 100644 --- a/README.md +++ b/README.md @@ -22,18 +22,19 @@ groups. Available colors are: blue, black, yellow, cyan, green, magenta, white, red, rainbow, random, Random, Spectrum, spectrum, scale, Scale, hash, Hash, none, an -RGB hexadecimal triplet or any number between 0 and 255. +RGB hexadecimal triplet (`#11aaff`, for example) or any number between 0 and 255. Available styles are: normal, bold, faint, italic, underline, blink, rapid\_blink, reverse, conceal or random (some styles may have no effect, depending on your terminal). -`rainbow` will cycle over a 6 colors rainbow at each matching pattern. -`Rainbow` will do the same over 24 colors (this requires a terminal that supports -the 256 color escape sequences). +`rainbow` will cycle over a the default colormap at each matching pattern. +`Rainbow` will do the same over the default colormap for the 256-colors mode +(this requires a terminal that supports the 256 color escape sequences). -`Random` will color each matching pattern with a random color among the 255 -available in the ANSI table. `random` will do the same in 8 colors mode. +`Random` will color each matching pattern with a random color among the default colormap +(the 255 available in the ANSI table, by default). +`random` will do the same in 8 colors mode. `spectrum` and `Spectrum` are like rainbows, but with more colors (8 and 36 colors). @@ -133,12 +134,11 @@ Gentoo Search for additional palettes (\*.gpl files) in this directory. * `-d COLORMAP`, `--default COLORMAP`: - When using special colormaps (`scale` or `hash`), use this COLORMAP instead of the `spectrum` one. + When using special colormaps (`random`, `scale` or `hash`), use this COLORMAP instead of the default one. This can be either one of the available colormaps or a comma-separated list of colors. - WARNING: be sure to specify a default colormap that is compatible with the special colormap's mode. - For instance, if you indicate `scale`, you can use `-d red,green,blue`, but `-d 12,13,14` will fail. - Also, if you specify `Scale`, you cannot use `-d red,green,blue`, but `-d Rainbow` will work. - Similarly, external palettes are converted from RGB to 256-ANSI and will thus not work if you use + WARNING: be sure to specify a default colormap that is compatible with the special colormap's mode, + or else the colors may not appear the same. + Also, external palettes are converted from RGB to 256-ANSI and will thus not work if you use them as default colormaps for a 8-colors mode special color. * `-r TYPE(S)`, `--resources TYPE(S)`: diff --git a/colout/colout.py b/colout/colout.py index f73533c..3d3ebc0 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -329,7 +329,8 @@ def color_random( color ): global context m = mode(color) if m == 8: - color_code = random.choice(context["colormaps"]["random"]) + color_name = random.choice(context["colormaps"]["random"]) + color_code = context["colors"][color_name] color_code = str(30 + color_code) elif m == 256: @@ -860,7 +861,7 @@ def __args_parse__(argv, usage=""): help="Search for additional palettes (*.gpl files) in the given directory") parser.add_argument("-d", "--default", metavar="COLORMAP", default=None, - help="When using special colormaps (`scale` or `hash`), use this COLORMAP. \ + help="When using special colormaps (`random`, `scale` or `hash`), use this COLORMAP. \ This can be either one of the available colormaps or a comma-separated list of colors. \ WARNING: be sure to specify a default colormap that is compatible with the special colormap's mode.")