From 8ed3cf136db610575c1be16d511d9cb665a306c7 Mon Sep 17 00:00:00 2001 From: dongweiming <6196225@qq.com> Date: Mon, 22 Apr 2013 17:40:12 +0800 Subject: [PATCH 1/6] Pygments is not installed, can not use the "-s python" --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bb9fb52..e4994f3 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ if sys.argv[-1] == 'publish': packages = ['colout'] -requires = [] +requires = ['pygments'] setup( name='colout', From 0f5b91ccecd44d6e4f16f0bef02099d6492239fe Mon Sep 17 00:00:00 2001 From: John Anderson Date: Sun, 5 May 2013 19:50:08 +0800 Subject: [PATCH 2/6] Add some essential resources --- AUTHORS | 6 ++ CHANGES | 4 ++ PKG-INFO | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++ README | 168 ++++++++++++++++++++++++++++++++++++++++++++ run-tests.py | 0 5 files changed, 373 insertions(+) create mode 100644 AUTHORS create mode 100644 CHANGES create mode 100644 PKG-INFO create mode 100644 README create mode 100644 run-tests.py diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..63be891 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,6 @@ +Colout is written by nojhan and maintained by Dongweiming: + +Writer +`````` + +- Nojhan \ No newline at end of file diff --git a/CHANGES b/CHANGES new file mode 100644 index 0000000..8fbff91 --- /dev/null +++ b/CHANGES @@ -0,0 +1,4 @@ +Version 0.1 +----------- + +Released on May 5th 2013, First public preview release. \ No newline at end of file diff --git a/PKG-INFO b/PKG-INFO new file mode 100644 index 0000000..26455a4 --- /dev/null +++ b/PKG-INFO @@ -0,0 +1,195 @@ +Metadata-Version: 1.1 +Name: Colout +Version: 0.1 +Summary: Color text streams with this simple command +Home-page: http://nojhan.github.com/colout/ +Author: Nojhan +Author-email: nojhan@nojhan.net +License: GPL3 +Description: + Colout + ----- + + Colout is Color text streams with this simple commandinja 2 and good + intentions. And before you ask: It's BSD licensed! + + SYNOPSIS + ```````````` + + ``colout`` [-h][-e] [-g][-t] [-s][-l] PATTERN [COLOR(S)][STYLE(S)] + + DESCRIPTION + ````````````````` + + ``colout`` read lines of text stream on the standard input and output + characters 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 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 groups. + + Available colors are: blue, black, yellow, cyan, green, magenta, white, + red, rainbow, random, Random, scale, none or any number between 0 and + 255. + + Available styles are: normal, bold, faint, italic, underline, blink, + rapid\_blink, reverse, conceal or random. + + ``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 a scale defined by the + ``-l`` option (see below, [0-100] by default). + + 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 (see the ``-t`` switch below). + + If the python-pygments library is available, ``colout`` can be used as + an interface to it (see also the ``-s`` switch below). + + ``colout`` is released under the GNU Public License v3. + + OPTIONS + ``````` + + - ``-h``, ``--help``: Show an help message and exit + + - ``-g``, ``--groups``: For color maps (like "rainbow"), iterate over + matching groups in the pattern instead of over patterns. + + - ``-c``, ``--colormap``: Use the given list of comma-separated colors + as a colormap (cycle the colors at each match). + + - ``-l``, ``--scale``: When using the 'scale' colormap, parse matches + as decimal numbers (taking your locale into account) and apply the + rainbow colormap linearly between the given SCALE=min,max + (SCALE=0,100, by default). + + - ``-a``, ``--all``: Color the whole input at once instead of line per + line (really useful for coloring a source code file with strings on + multiple lines). + + - ``-t``, ``--theme``: Interpret PATTERN as a predefined theme (perm, + cmake, g++, etc.) + + - ``-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"). + + + REGULAR EXPRESSIONS + ``````````````````` + + 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`` is generally called by the command line, you may + have to escape special characters that would be recognize by your shell. + + DEPENDENCIES + ```````````` + + Recommended packages : + + - ``argparse`` for a usable arguments parsing + - ``pygments`` for the source code syntax coloring + - ``babel`` for a locale-aware number parsing + + EXAMPLES + ```````` + + - Color in bold red every occurence of the word *color* in colout + sources: ``cat colout.py | colout color red bold`` + + - Color in bold violet home directories in */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*: + ``colout ':x:([0-9]+:[0-9]+):([^:]+).*(/home/[a-z]+)' yellow,green,red normal,bold < /etc/passwd`` + + - Color in yellow file permissions with read rights for everyone: + ``ls -l | colout '.(r.-){3}' yellow normal`` + + - Color in green read permission, in bold red write and execution ones: + ``ls -l | colout '(r)(w*)(x*)' green,red normal,bold`` + + - Color permissions with a predefined template: + ``ls -l | colout -t perm`` + + - Color in green comments in colout sources: + ``colout '.*(#.*)$' green normal < colout.py`` + + - Color permissions with a predefined template: + ``ls -l | colout -t perm`` + + - Color in green comments in colout sources: + ``colout '.*(#.*)$' green normal < colout.py`` + + - Color in light green comments in non-empty colout sources, with the + sharp in bold green: + ``grep -v '^\s*$' colout.py | colout '.*(#)(.*)$' green,119 bold,normal`` + + - Color in bold green every numbers and in bold red the words *error* + in make output: + ``make 2>&1 | colout '[0-9]+' green normal | colout error`` + + - Color a make output, line numbers in yellow, errors in bold red, + warning in magenta, pragma in green and C++ file base names in cyan: + ``make 2>&1 | colout ':([0-9]+):[0-9]*' yellow normal | colout error | colout warning magenta | colout pragma green normal | colout '/(\w+)*\.(h|cpp)' cyan normal`` + Or using themes: ``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+": + ``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: + ``cat colout.py | grep -v "#" | colout -s python`` + + - Color a source code in 256 colors mode: + ``cat colout.py | colout -s Python monokai`` + + - Color a JSON stream: + ``echo '{"foo": "lorem", "bar":"ipsum"}' | python -mjson.tool | colout -t json`` + + - Color a source code substring: + ``echo "There is an error in 'static void Functor::operator()( EOT& indiv ) { return indiv; }' you should fix it" | colout "'(.*)'" Cpp monokai`` + + + + +Platform: any +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Console +Classifier: Intended Audience :: End Users/Desktop +Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2.5 +Classifier: Programming Language :: Python :: 2.6 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Topic :: Text Processing +Classifier: Topic :: Utilities +Classifier: Topic :: Software Development :: Libraries :: Python Modules \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..bff5af3 --- /dev/null +++ b/README @@ -0,0 +1,168 @@ +Colout +----- + +Colout is Color text streams with this simple commandinja 2 and good +intentions. And before you ask: It's BSD licensed! + +SYNOPSIS +```````````` + +``colout`` [-h][-e] [-g][-t] [-s][-l] PATTERN [COLOR(S)][STYLE(S)] + +DESCRIPTION +````````````````` + +``colout`` read lines of text stream on the standard input and output +characters 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 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 groups. + +Available colors are: blue, black, yellow, cyan, green, magenta, white, +red, rainbow, random, Random, scale, none or any number between 0 and +255. + +Available styles are: normal, bold, faint, italic, underline, blink, +rapid\_blink, reverse, conceal or random. + +``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 a scale defined by the +``-l`` option (see below, [0-100] by default). + +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 (see the ``-t`` switch below). + +If the python-pygments library is available, ``colout`` can be used as +an interface to it (see also the ``-s`` switch below). + +``colout`` is released under the GNU Public License v3. + +OPTIONS +``````` + +- ``-h``, ``--help``: Show an help message and exit + +- ``-g``, ``--groups``: For color maps (like "rainbow"), iterate over + matching groups in the pattern instead of over patterns. + +- ``-c``, ``--colormap``: Use the given list of comma-separated colors + as a colormap (cycle the colors at each match). + +- ``-l``, ``--scale``: When using the 'scale' colormap, parse matches + as decimal numbers (taking your locale into account) and apply the + rainbow colormap linearly between the given SCALE=min,max + (SCALE=0,100, by default). + +- ``-a``, ``--all``: Color the whole input at once instead of line per + line (really useful for coloring a source code file with strings on + multiple lines). + +- ``-t``, ``--theme``: Interpret PATTERN as a predefined theme (perm, + cmake, g++, etc.) + +- ``-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"). + + +REGULAR EXPRESSIONS +``````````````````` + +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`` is generally called by the command line, you may +have to escape special characters that would be recognize by your shell. + +DEPENDENCIES +```````````` + +Recommended packages : + +- ``argparse`` for a usable arguments parsing +- ``pygments`` for the source code syntax coloring +- ``babel`` for a locale-aware number parsing + +EXAMPLES +```````` + +- Color in bold red every occurence of the word *color* in colout + sources: ``cat colout.py | colout color red bold`` + +- Color in bold violet home directories in */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*: + ``colout ':x:([0-9]+:[0-9]+):([^:]+).*(/home/[a-z]+)' yellow,green,red normal,bold < /etc/passwd`` + +- Color in yellow file permissions with read rights for everyone: + ``ls -l | colout '.(r.-){3}' yellow normal`` + +- Color in green read permission, in bold red write and execution ones: + ``ls -l | colout '(r)(w*)(x*)' green,red normal,bold`` + +- Color permissions with a predefined template: + ``ls -l | colout -t perm`` + +- Color in green comments in colout sources: + ``colout '.*(#.*)$' green normal < colout.py`` + +- Color permissions with a predefined template: + ``ls -l | colout -t perm`` + +- Color in green comments in colout sources: + ``colout '.*(#.*)$' green normal < colout.py`` + +- Color in light green comments in non-empty colout sources, with the + sharp in bold green: + ``grep -v '^\s*$' colout.py | colout '.*(#)(.*)$' green,119 bold,normal`` + +- Color in bold green every numbers and in bold red the words *error* + in make output: + ``make 2>&1 | colout '[0-9]+' green normal | colout error`` + +- Color a make output, line numbers in yellow, errors in bold red, + warning in magenta, pragma in green and C++ file base names in cyan: + ``make 2>&1 | colout ':([0-9]+):[0-9]*' yellow normal | colout error | colout warning magenta | colout pragma green normal | colout '/(\w+)*\.(h|cpp)' cyan normal`` + Or using themes: ``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+": + ``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: + ``cat colout.py | grep -v "#" | colout -s python`` + +- Color a source code in 256 colors mode: + ``cat colout.py | colout -s Python monokai`` + +- Color a JSON stream: + ``echo '{"foo": "lorem", "bar":"ipsum"}' | python -mjson.tool | colout -t json`` + +- Color a source code substring: + ``echo "There is an error in 'static void Functor::operator()( EOT& indiv ) { return indiv; }' you should fix it" | colout "'(.*)'" Cpp monokai`` \ No newline at end of file diff --git a/run-tests.py b/run-tests.py new file mode 100644 index 0000000..e69de29 From 55d09b2858d5541c9d665177b77b6111264906c3 Mon Sep 17 00:00:00 2001 From: John Anderson Date: Sun, 5 May 2013 21:17:02 +0800 Subject: [PATCH 3/6] hotfix python3 install bug --- bin/colout | 4 ++-- setup.py | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/colout b/bin/colout index 9e09ae9..aedc3eb 100644 --- a/bin/colout +++ b/bin/colout @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright © 2013 Martin Ueding +# Copyright @ 2013 Martin Ueding # Small launcher script for the main module. @@ -8,4 +8,4 @@ set -e set -u -python3 -m colout.colout "$@" +python -m colout.colout "$@" diff --git a/setup.py b/setup.py index 8b25d51..1e208a8 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python +#coding=utf-8 import os import sys -#import colout - try: from setuptools import setup except ImportError: @@ -39,17 +38,17 @@ setup( version='0.1', description='Color Up Arbitrary Command Ouput.', long_description=open('README').read(), - author='nojhan', + author='Nojhan', author_email='nojhan@nojhan.net', url='http://nojhan.github.com/colout/', - download_url = 'https://pypi.python.org/packages/source/C/colout/colout-0.1.tar.gz', + download_url = 'https://pypi.python.org/packages/source/c/colout/colout-0.1.tar.gz', packages=packages, package_data={'': ['LICENSE']}, package_dir={'colout': 'colout'}, scripts=['bin/colout'], include_package_data=True, install_requires=requires, - license=open('LICENSE').read(), + license="GPL 3", classifiers = filter(None, classifiers.split("\n")), zip_safe=False, ) From e868b738fffb524c2a3624f8d1236e3389ceb67c Mon Sep 17 00:00:00 2001 From: John Anderson Date: Mon, 3 Jun 2013 00:18:02 +0800 Subject: [PATCH 4/6] Update --- README | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index bff5af3..9d51126 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ Colout ----- Colout is Color text streams with this simple commandinja 2 and good -intentions. And before you ask: It's BSD licensed! +intentions. SYNOPSIS ```````````` diff --git a/setup.py b/setup.py index 1e208a8..cd9b398 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ setup( scripts=['bin/colout'], include_package_data=True, install_requires=requires, - license="GPL 3", + license="GPL-3", classifiers = filter(None, classifiers.split("\n")), zip_safe=False, ) From a7908c47e9611328a766c4778ba1f87df2121482 Mon Sep 17 00:00:00 2001 From: dongweiming Date: Sat, 8 Jun 2013 00:10:14 +0800 Subject: [PATCH 5/6] hotfix python3 install bug --- README | 166 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 165 deletions(-) diff --git a/README b/README index 9d51126..7a5a505 100644 --- a/README +++ b/README @@ -1,168 +1,4 @@ Colout ----- -Colout is Color text streams with this simple commandinja 2 and good -intentions. - -SYNOPSIS -```````````` - -``colout`` [-h][-e] [-g][-t] [-s][-l] PATTERN [COLOR(S)][STYLE(S)] - -DESCRIPTION -````````````````` - -``colout`` read lines of text stream on the standard input and output -characters 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 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 groups. - -Available colors are: blue, black, yellow, cyan, green, magenta, white, -red, rainbow, random, Random, scale, none or any number between 0 and -255. - -Available styles are: normal, bold, faint, italic, underline, blink, -rapid\_blink, reverse, conceal or random. - -``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 a scale defined by the -``-l`` option (see below, [0-100] by default). - -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 (see the ``-t`` switch below). - -If the python-pygments library is available, ``colout`` can be used as -an interface to it (see also the ``-s`` switch below). - -``colout`` is released under the GNU Public License v3. - -OPTIONS -``````` - -- ``-h``, ``--help``: Show an help message and exit - -- ``-g``, ``--groups``: For color maps (like "rainbow"), iterate over - matching groups in the pattern instead of over patterns. - -- ``-c``, ``--colormap``: Use the given list of comma-separated colors - as a colormap (cycle the colors at each match). - -- ``-l``, ``--scale``: When using the 'scale' colormap, parse matches - as decimal numbers (taking your locale into account) and apply the - rainbow colormap linearly between the given SCALE=min,max - (SCALE=0,100, by default). - -- ``-a``, ``--all``: Color the whole input at once instead of line per - line (really useful for coloring a source code file with strings on - multiple lines). - -- ``-t``, ``--theme``: Interpret PATTERN as a predefined theme (perm, - cmake, g++, etc.) - -- ``-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"). - - -REGULAR EXPRESSIONS -``````````````````` - -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`` is generally called by the command line, you may -have to escape special characters that would be recognize by your shell. - -DEPENDENCIES -```````````` - -Recommended packages : - -- ``argparse`` for a usable arguments parsing -- ``pygments`` for the source code syntax coloring -- ``babel`` for a locale-aware number parsing - -EXAMPLES -```````` - -- Color in bold red every occurence of the word *color* in colout - sources: ``cat colout.py | colout color red bold`` - -- Color in bold violet home directories in */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*: - ``colout ':x:([0-9]+:[0-9]+):([^:]+).*(/home/[a-z]+)' yellow,green,red normal,bold < /etc/passwd`` - -- Color in yellow file permissions with read rights for everyone: - ``ls -l | colout '.(r.-){3}' yellow normal`` - -- Color in green read permission, in bold red write and execution ones: - ``ls -l | colout '(r)(w*)(x*)' green,red normal,bold`` - -- Color permissions with a predefined template: - ``ls -l | colout -t perm`` - -- Color in green comments in colout sources: - ``colout '.*(#.*)$' green normal < colout.py`` - -- Color permissions with a predefined template: - ``ls -l | colout -t perm`` - -- Color in green comments in colout sources: - ``colout '.*(#.*)$' green normal < colout.py`` - -- Color in light green comments in non-empty colout sources, with the - sharp in bold green: - ``grep -v '^\s*$' colout.py | colout '.*(#)(.*)$' green,119 bold,normal`` - -- Color in bold green every numbers and in bold red the words *error* - in make output: - ``make 2>&1 | colout '[0-9]+' green normal | colout error`` - -- Color a make output, line numbers in yellow, errors in bold red, - warning in magenta, pragma in green and C++ file base names in cyan: - ``make 2>&1 | colout ':([0-9]+):[0-9]*' yellow normal | colout error | colout warning magenta | colout pragma green normal | colout '/(\w+)*\.(h|cpp)' cyan normal`` - Or using themes: ``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+": - ``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: - ``cat colout.py | grep -v "#" | colout -s python`` - -- Color a source code in 256 colors mode: - ``cat colout.py | colout -s Python monokai`` - -- Color a JSON stream: - ``echo '{"foo": "lorem", "bar":"ipsum"}' | python -mjson.tool | colout -t json`` - -- Color a source code substring: - ``echo "There is an error in 'static void Functor::operator()( EOT& indiv ) { return indiv; }' you should fix it" | colout "'(.*)'" Cpp monokai`` \ No newline at end of file +This is the [colout](http://nojhan.github.com/colout/)'s pypi source From cf3370988b7dcac6c8c1e730fce4f2ff144a4a7c Mon Sep 17 00:00:00 2001 From: Charles Lewis Date: Mon, 10 Jun 2013 21:45:04 -0400 Subject: [PATCH 6/6] bugfix #40: don't try to color non-matching groups --- colout/colout.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index 0f7cfc3..0ac5a39 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -304,8 +304,10 @@ def colorup(text, pattern, color="red", style="normal", on_groups=False): # but that match.start(0) refers to the whole match, the groups being indexed in [1,n]. # Thus, we need to range in [1,n+1[. for group in range(1, nb_groups+1): - partial, end = colorout(text, match, end, group_colors[group-1], group_styles[group-1], group) - colored_text += partial + # If a group didn't match, there's nothing to color + if match.group(group) is not None: + partial, end = colorout(text, match, end, group_colors[group-1], group_styles[group-1], group) + colored_text += partial # Append the remaining part of the text, if any. colored_text += text[end:]