From f082dbc3a2898960df6f98d8ac71d8a129e4e497 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 5 Jun 2013 13:19:03 +0200 Subject: [PATCH 1/7] feature #35: show colors tags in debug mode --- colout/colout.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index 7b1ff80..59fffa8 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -259,6 +259,7 @@ def colorin(text, color="red", style="normal"): assert( type(color) is str ) global colormap_idx + global debug # Special characters. start = "\033[" @@ -276,7 +277,10 @@ def colorin(text, color="red", style="normal"): if color == "none": # if no color, style cannot be applied - return text + if not debug: + return text + else: + return ""+text+"" elif color == "random": mode = 8 @@ -388,13 +392,19 @@ def colorin(text, color="red", style="normal"): formatter = TerminalFormatter(bg=style) # We should return all but the last character, # because Pygments adds a newline char. - return highlight(text, lexer, formatter)[:-1] + if not debug: + return highlight(text, lexer, formatter)[:-1] + else: + return "<"+color+">"+ highlight(text, lexer, formatter)[:-1] + "" # unrecognized else: raise UnknownColor(color) - return start + style_code + endmarks[mode] + color_code + "m" + text + stop + if not debug: + return start + style_code + endmarks[mode] + color_code + "m" + text + stop + else: + return start + style_code + endmarks[mode] + color_code + "m<" + color + ">" + text + "" + stop def colorout(text, match, prev_end, color="red", style="normal", group=0): From 5026751c4185f8447b1b43a977a5335382a3d1f1 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 5 Jun 2013 20:08:00 +0200 Subject: [PATCH 2/7] Add debug mode for re.compile --- colout/colout.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/colout/colout.py b/colout/colout.py index 59fffa8..9bf991c 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -444,7 +444,11 @@ def colorup(text, pattern, color="red", style="normal", on_groups=False): '\x1b[1;34mF\x1b[0m\x1b[3;34maites\x1b[0m \x1b[1;34mC\x1b[0m\x1b[3;34mhier\x1b[0m la Vache' """ global colormap_idx - regex = re.compile(pattern) # , re.IGNORECASE) + + if not debug: + regex = re.compile(pattern) + else: + regex = re.compile(pattern, re.DEBUG) # Prepare the colored text. colored_text = "" From f617d9c30251897931ce2e892c9c4b74c03a3d74 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 5 Jun 2013 21:24:25 +0300 Subject: [PATCH 3/7] LIMITATIONS section in the README Don't use nested groups or colout will duplicate the corresponding input text with each matching colors. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9da7137..f6dedae 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,11 @@ Recommended packages : * `babel` for a locale-aware number parsing +## LIMITATIONS + +Don't use nested groups or colout will duplicate the corresponding input text with each matching colors. + + ## EXAMPLES * Color in bold red every occurence of the word _color_ in colout sources: From d1ec964c0fcf6876ff33de9cf211cbf2d5209547 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 5 Jun 2013 21:26:40 +0300 Subject: [PATCH 4/7] better README synopsis --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6dedae..04f23d9 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ colout(1) -- Color Up Arbitrary Command Ouput ## SYNOPSIS -`colout` [-h] [-g] [-c] [-l] [-a] [-t] [-T] [-s] PATTERN [COLOR(S)] [STYLE(S)] +`colout` [-h] [-r] + +`colout` [-g] [-c] [-l] [-a] [-t] [-T] [-P] [-s] PATTERN [COLOR(S) [STYLE(S)]] ## DESCRIPTION From d030cc9d3c62b34ce5c2522b3ffbdf1002355c08 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 5 Jun 2013 20:45:57 +0200 Subject: [PATCH 5/7] correct colormaps sizes in README --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 04f23d9..1ed0007 100644 --- a/README.md +++ b/README.md @@ -29,14 +29,16 @@ 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 8 colors rainbow at each matching pattern. +`Rainbow` will do the same over 24 colors (necessitate a terminal compatible +with 256-colors mode). + `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. -`rainbow` will cycle over a 8 colors rainbow at each matching pattern. - -`scale` will parse the matching text as a decimal number and apply the rainbow -colormap according to its position on the scale defined by the `-l` option (see -below, [0-100] by default). +`scale` (8 colors) and `Scale` (36 colors) will parse the matching text as +a decimal number and apply the rainbow colormap according to its position +on the scale defined by the `-l` option (see below, "0,100" by default). 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.). From fca426ca066bbcac688d2c7b20a704bf0f038d2a Mon Sep 17 00:00:00 2001 From: Brian Foley Date: Thu, 6 Jun 2013 20:06:34 +0100 Subject: [PATCH 6/7] Miscellaneous README spelling and grammar tweaks --- README.md | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 1ed0007..d67c5c1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -colout(1) -- Color Up Arbitrary Command Ouput -============================================= +colout(1) -- Color Up Arbitrary Command Output +============================================== ## SYNOPSIS @@ -16,9 +16,9 @@ matching a given regular expression *PATTERN* in given and *STYLE*. If groups are specified in the regular expression pattern, only them are taken into account, else the whole matching pattern is colored. -You can specify severall colors or styles when using groups by separating them +You can specify several colors or styles when using groups by separating them with commas. If you indicate more colors than groups, the last ones will be ignored. -If you ask for less colors, the last one will be duplicated across remaining +If you ask for fewer colors, the last one will be duplicated across remaining groups. Available colors are: blue, black, yellow, cyan, green, magenta, white, red, @@ -30,8 +30,8 @@ rapid_blink, reverse, conceal or random (some styles may have no effect, dependi on your terminal). `rainbow` will cycle over a 8 colors rainbow at each matching pattern. -`Rainbow` will do the same over 24 colors (necessitate a terminal compatible -with 256-colors mode). +`Rainbow` will do the same over 24 colors (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. @@ -47,11 +47,11 @@ If GIMP palettes files (*.gpl) are available, you can also use their names as a colormap (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. +be converted to their nearest ANSI 256 color mode equivalents. When not specified, a *COLOR* defaults to _red_ and a *STYLE* defaults to _bold_. -`colout` comes with some predefined themes to rapidely color well-known outputs +`colout` comes with some predefined themes to rapidly color well-known outputs (see the `-t` switch below). If the python-pygments library is available, `colout` can be used as an interface @@ -67,14 +67,15 @@ use the `-r` switch (see below). sudo python setup.py install -and then soft link `/usr/local/bin/colout` to your colout.py under your installaion directory, which usually like +and then soft link `/usr/local/bin/colout` to your colout.py under your installation +directory, which is usually something like /usr/local/lib/python2.7/dist-packages/colout-0.1-py2.7.egg/colout/colout.py ## OTHER INSTALLATION METHOD -Pypi(the Python Package Index) +Pypi (the Python Package Index) sudo pip install colout @@ -127,7 +128,7 @@ Gentoo overlay ## OPTIONS * `-h`, `--help`: - Show an help message and exit + Show a help message and exit * `-g`, `--groups`: For color maps (like "rainbow"), iterate over matching groups in the pattern instead of over patterns. @@ -136,7 +137,7 @@ Gentoo overlay Use the given list of comma-separated colors as a colormap (cycle the colors at each match). * `-a`, `--all` - Color the whole input at once instead of line per line (really useful + Color the whole input at once instead of line by line (really useful for coloring a source code file with strings on multiple lines). * `-l min,max`, `--scale min,max`: @@ -160,9 +161,9 @@ for coloring a source code file with strings on multiple lines). Print the names of all available colors, styles, themes and palettes. * `-s`, `--source`: - Interpret PATTERN as a source code readable by the Pygments library. If the first letter of PATTERN - is upper case, use the 256 colors mode, if it is lower case, use the 8 colors mode. - In 256 colors, interpret COLOR as a Pygments style (e.g. "default"). + Interpret PATTERN as source code readable by the Pygments library. If the first letter of PATTERN + is upper case, use the 256 color mode, if it is lower case, use the 8 colors mode. + In 256 color mode, interpret COLOR as a Pygments style (e.g. "default"). * `--debug`: Debug mode: print what's going on internally, if you want to check what features are available. @@ -173,14 +174,14 @@ for coloring a source code file with strings on multiple lines). A regular expression (or _regex_) is a pattern that describes a set of strings that matches it. -`colout` understands regex as specifed in the _re_ python module. Given that +`colout` understands regex as specified in the _re_ python module. Given that `colout` is generally called by the command line, you may have to escape special characters that would be recognize by your shell. ## DEPENDENCIES -Recommended packages : +Recommended packages: * `argparse` for a usable arguments parsing * `pygments` for the source code syntax coloring @@ -194,7 +195,7 @@ Don't use nested groups or colout will duplicate the corresponding input text wi ## EXAMPLES -* Color in bold red every occurence of the word _color_ in colout sources: +* Color in bold red every occurrence of the word _color_ in colout sources: `cat colout.py | colout color red bold` * Color in bold violet home directories in _/etc/passwd_: @@ -230,16 +231,16 @@ Don't use nested groups or colout will duplicate the corresponding input text wi `make 2>&³ | colout -t cmake | colout -t g++` * Color each word in the head of auth.log with a rainbow color map, starting a new colormap at each new line (the - begining of the command is just bash magic to repeat the string "(\\w+)\\W+": + beginning of the command is just bash magic to repeat the string "(\\w+)\\W+": `L=$(seq 10) ; P=${L//??/(\\w+)\\W+} ; head /var/log/auth.log | colout -g "^${P}(.*)$" rainbow` * Color each line of a file with a different color among a 256 color gradient from cyan to green: `head /var/log/auth.log | colout -c "^.*$" 39,38,37,36,35,34` -* Color a source code in 8 colors mode, without seeing comments: +* Color source code in 8 colors mode, without seeing comments: `cat colout.py | grep -v "#" | colout -s python` -* Color a source code in 256 colors mode: +* Color source code in 256 color mode: `cat colout.py | colout -s Python monokai` * Color a JSON stream: From 47282a9408e9fe9dd9a2614d402f5df2e2cf9a7d Mon Sep 17 00:00:00 2001 From: dongweiming Date: Fri, 7 Jun 2013 23:12:12 +0800 Subject: [PATCH 7/7] colout has add to gentoo main portage tree --- README.md | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 1ed0007..992a525 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ colout(1) -- Color Up Arbitrary Command Ouput `colout` [-g] [-c] [-l] [-a] [-t] [-T] [-P] [-s] PATTERN [COLOR(S) [STYLE(S)]] - ## DESCRIPTION `colout` read lines of text stream on the standard input and output characters @@ -88,41 +87,9 @@ Ubuntu 13.04's ppa sudo apt-get update sudo apt-get/aptitude install colout -Gentoo overlay - - 1. Install layman - - echo "app-portage/layman git" >> $EPREFIX/etc/portage/package.Use - sudo emerge layman - - 2. Edit `$EPREFIX/etc/layman/layman.cfg`. Add a line after - - overlays : http://www.gentoo.org/proj/en/overlays/repositories.xml - - so that it becomes - - overlays : http://www.gentoo.org/proj/en/overlays/repositories.xml - file://$EPREFIX/var/lib/layman/my-list.xml - - 3. Edit `$EPREFIX/var/lib/layman/my-list.xml`. The content of this file should be: - - - - - dongwm-overlay - dongweiming's gentoo overlay - https://github.com/dongweiming/dongwm-overlay.git - - ciici1234@hotmail.com - - git://github.com/dongweiming/dongwm-overlay.git - - - - 4. Add this overlay and installation - - layman -a dongwm-overlay && sudo emerge colout +Gentoo + sudo emerge colout ## OPTIONS