Git Product home page Git Product logo

colout's Introduction

colout — Color Up Arbitrary Command Output

Colout logo

Synopsis

colout [-h] [-r [RESOURCE]]

colout [-g] [-c] [-l min,max] [-a] [-t] [-T DIR] [-P DIR] [-d COLORMAP] [-s] [-e CHAR] [-E CHAR] [--debug] 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 COLOR 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 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 fewer colors, the last one will be duplicated across remaining 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 (#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).

In some case, you can indicate a foreground and a background color, by indicating both colors separated by a period (for example: red.blue). You can also use this system to combine two styles (for example, for a bold style that also blinks: bold.blink).

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 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).

scale (8 colors) and Scale (256 colors) will parse the numbers characters in the matching text as a decimal number and apply the default colormap according to its position on the scale defined by the -l option (see below, "0,100" by default).

hash (8 colors) and Hash (256 colors) will take a fingerprint of the matching text and apply the default colormap according to it. This ensure that matching texts appearing several times will always get the same color.

Before interpreting the matched string as a number, colout will remove any character not supposed to be used to write down numbers. This permits to apply this special color on a large group, while interpreting only its numerical part.

You can use the name of a 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 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 color mode equivalents.

When not specified, a COLOR defaults to red and a STYLE defaults to bold.

colout comes with some predefined themes to rapidly color well-known outputs (see the -t switch below).

colout can be used as an interface to pygments (see also the --source switch below).

To have a list of all colors, styles, special colormaps, themes, palettes and lexers, use the -r switch (see below).

colout is released under the GNU Public License v3.

Installation

The recomended method is using pip to install the package for the local user:

$ pip install --user colout

Another method is using pipsi (pipsi is no longer maintained, https://github.com/mitsuhiko/pipsi/blob/db3e3fccbe4f8f9ed1104ed7293ec8fec6579efc/README.md#L3)

$ pipsi install colout

There is also a PPA for Ubuntu 16.04 (Xenial)/18.04 (Bionic) (@0.6.1-3~dist7, not actively maintained)

$ sudo add-apt-repository ppa:csaba-kertesz/random
$ sudo apt-get update
$ sudo apt-get/aptitude install colout

Options

  • -h, --help: Show a 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 min,max, --scale min,max: When using the 'scale' colormap, parse matches as decimal numbers (taking your locale into account) or as arithmetic expression (like "1+2/0.9*3") and apply the rainbow colormap linearly between the given min,max (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.).

  • -T DIR, --themes-dir DIR: Search for additional themes (colout_*.py files) in this directory.

  • -P DIR, --palettes-dir DIR: Search for additional palettes (*.gpl files) in this directory.

  • -d COLORMAP, --default COLORMAP: 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, 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)]: Print the names of available resources. Use a comma-separated list of resources names (styles, colors, special, themes, palettes, colormaps or lexers), use 'all' (or no argument) to print all resources.

  • -s, --source: 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").

  • -e CHAR, --sep-list CHAR: Use this character as a separator for list of colors/resources/numbers (instead of comma).

  • -E CHAR, --sep-pair CHAR: Use this character as a separator for foreground/background pairs (instead of period).

  • --debug: Debug mode: print what's going on internally, if you want to check what features are available.

Regular expressions

A regular expression (or regex) is a pattern that describes a set of strings that matches it.

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

Necessary Python modules:

  • pygments for the source code syntax coloring
  • 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.

Using a default colormap that is incompatible with the special colormap's mode (i.e. number of colors) will end badly.

Color pairs (foreground.background) work in 8-colors mode for simple coloring, but may fail with --colormap.

Examples

Simple

  • 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: colout '/home/[a-z]+' 135 < /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]+):([^:]+).*(/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 in green comments in colout sources: colout '.*(#.*)$' green normal < colout.py

  • 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

Somewhat useful

  • Use a different color for each line of the auth log grep user /var/log/auth.log | colout "^.*$" 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 permissions with a predefined template: ls -l | colout -t perm

  • 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 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>&1 | 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 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 source code in 8 colors mode, without seeing comments: cat colout.py | grep -v "#" | colout -s python

  • Color source code in 256 color 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

  • Color the percent of progress part of a CMake's makefile output, with a color related to the value of the progress (from 0%=blue to 100%=red): cmake .. && make | colout "^(\[\s*[0-9]+%\])" Scale

  • Color hosts and users in auth.log, with consistent colors: cat /var/log/auth.log | colout "^(\S+\s+){3}(\S+)\s(\S+\s+){3}(\S+)\s+(\S+\s+){2}(\S+)\s*" none,hash,none,hash,none,hash

Bash alias

The following bash function color the output of any command with the cmake and g++ themes:

function cm()
{
    set -o pipefail
    $@ 2>&1  | colout -t cmake | colout -t g++
}

You then can use the cm alias as a prefix to your build command, for example: cm make test

GDB integration

You can use colout within the GNU debuger (gbd) to color its output. For example, the following script .gdbinit configuration will color the output of the backtrace command:

set confirm off

# Don't wrap line or the coloring regexp won't work.
set width 0

# Create a named pipe to get outputs from gdb
shell test -e /tmp/coloutPipe && rm /tmp/coloutPipe
shell mkfifo /tmp/coloutPipe

define logging_on
  # Instead of printing on stdout only, log everything...
  set logging redirect on
  # ... in our named pipe.
  set logging on /tmp/coloutPipe
end

define logging_off
  set logging off
  set logging redirect off
  # Because both gdb and our commands are writing on the same pipe at the same
  # time, it is more than probable that gdb will end before our (higher level)
  # commands.  The gdb prompt will thus render before the result of the command,
  # which is highly akward. To prevent this, we need to wait before displaying
  # the prompt again.  The more your commands are complex, the higher you will
  # need to set this.
  shell sleep 0.4s
end

define hook-backtrace
    # Note: match path = [path]file[.ext] = (.*/)?(?:$|(.+?)(?:(\.[^.]*)|))
    # This line color highlights:
    # – lines that link to source code,
    # – function call in green,
    # – arguments names in yellow, values in magenta,
    # — the parent directory in bold red (assuming that the debug session would be in a "project/build/" directory).
    shell cat /tmp/coloutPipe | colout "^(#)([0-9]+)\s+(0x\S+ )*(in )*(.*) (\(.*\)) (at) (.*/)?(?:$|(.+?)(?:(\.[^.]*)|)):([0-9]+)" red,red,blue,red,green,magenta,red,none,white,white,yellow normal,bold,normal,normal,normal,normal,normal,bold,bold,bold | colout "([\w\s]*?)(=)([^,]*?)([,\)])" yellow,blue,magenta,blue normal | colout "/($(basename $(dirname $(pwd))))/" red bold &
    logging_on
end
define hookpost-backtrace
    logging_off
end

# Don't forget to clean the adhoc pipe.
define hook-quit
    set confirm off
    shell rm -f /tmp/coloutPipe
end

Take a look at the example.gdbinit file distributed with colout for more gdb commands.

Themes

You can easily add your own theme to colout. A theme is basically a module with a function named theme that take the configuration context as an argument and return back the (modified) context and a list of triplets. Each triplet figures the same arguments than those of the command line interface.

def theme(context):
    return context,[ [regexp, colors, styles] ]

With the context dictionary at hand, you have access to the internal configuration of colout, you can thus change colormaps for special keywords, the scale, even the available colors, styles or themes.

See the cmake them for how to modify an existing colormap if (and only if) the user didn't ask for an alternative one. See the ninja theme for how to extend an existing theme with more regexps and a different configuration. See the gcc theme for an example of how to use the localization of existing softwares to build translated regexp.

Buffering

Note that when you use colout within real time streams (like tail -f X | grep Y | colout Z) of commands, you may observe that the lines are printed by large chunks and not one by one, in real time. This is not due to colout but to the buffering behavior of your shell.

To fix that, use stdbuf, for example: tail -f X | stdbuf -o0 grep Y | colout Z.

Authors

colout's People

Contributors

blastrock avatar bpfoley avatar code0x58 avatar daindwarf avatar dmerejkowsky avatar dongwm avatar doodleincident avatar durka avatar jason-green-io avatar jdreo avatar jonathanpoelen avatar jquast avatar kecsap avatar linkmauve avatar louiskenzo avatar martin-ueding avatar necior avatar nojhan avatar np avatar oczkers avatar orzrd avatar oz-linden avatar pconst avatar sirex avatar sontek avatar stdedos avatar thefab avatar while0pass avatar xudifsd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colout's Issues

Debug mode

Add a debug mode that will output what's going on with external ressources (missing dependencies warnings, what lexers/palettes/themes are loaded).

Shortcuts to pygments and json

Add options to use colout as a proxy to pygments and the json module: echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool

colout override the previous color

If I use colout with this command:

ls -F --color=auto | colout "...." ...

The color build by ls is overide by colout. A flag argument should control this behaviour.

Problem with utf-8 when using translated mo

Hi o/

On archlinux the language file for gcc (and g++) are in: /usr/share/locale/fr/LC_MESSAGES/gcc.mo

So I modify colout_g++.py from "gcc-version" to "gcc".

When I use this theme I got:
Traceback (most recent call last):
File "/usr/lib/python3.3/runpy.py", line 160, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python3.3/runpy.py", line 73, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.3/site-packages/colout/colout.py", line 842, in
write_all( as_all, sys.stdin, sys.stdout, colortheme, themes[pattern].theme() )
File "./colout_g++.py", line 18, in theme
t = gettext.translation("gcc")
File "/usr/lib/python3.3/gettext.py", line 410, in translation
t = translations.setdefault(key, class(fp))
File "/usr/lib/python3.3/gettext.py", line 160, in init
self._parse(fp)
File "/usr/lib/python3.3/gettext.py", line 265, in _parse
item = b_item.decode().strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 21: invalid continuation byte

My locale is UTF-8: LANG=fr_FR.UTF-8

Code refactoring

We need to factorize source and themes with ANSI colors handling.

Update version on PyPI

Not really a code comment, but I just discovered colout and it looks awesome... so I tried installing it to test with pip. Which worked, but then I found that the output doesn't look like in the web page docs, some of the commands (for example using -P) don't work, etc. A bit surprising...

Looking on PyPI I see that the only version on there is 0.1, last updated in May, despite it being mentioned in the docs as one of the ways to get colout. It seems a lot has happened since then! Could a new version be uploaded to PyPI, please? Thanks!

Wrong default colormap selected

Your last commit d6452a6 seems to have broken themes in a strange way:

echo '[  5%] Building CXX object CMakeFiles/qi.dir/src/path.cpp.o'  | python3 colout.py -t cmake 
[0;38;5;bluem[  5%] Building CXX object CMakeFiles/qi.dir/src/path.cpp.o

My terminal does not seem to support 8 color maps, but let's ignore that fact, the problem is that I want to use 256 color maps and I can't. This is related to the default colormap used. To work around this, one must put any word starting with a capital letter as the color argument so that you get the right colormap near line 932 . This works:

echo '[  5%] Building CXX object CMakeFiles/qi.dir/src/path.cpp.o'  | python3 colout.py -t cmake Whatever
[  5%] Building CXX object CMakeFiles/qi.dir/src/path.cpp.o

This seems like a strange behavior to me, but maybe I'm getting something wrong here. Also colout -t cmake -d Spectrum always selects spectrum (without the capital) and I couldn't get the Spectrum map working.

A fix would be to replace lines 931 to 935 by cmap = default_colormap

EDIT: got the line numbers wrong :P

Problems with $LC_ALL, $LANG and $LANGUAGE

With my settings :

LC_ALL=fr_FR.UTF-8
LANG=C
LANGUAGE=C

I get

make -j 17 test/test_runner 2>&1 | ~/repo/colout/colout.py -t g++
/Soft/team/linux/gcc-4.7.2/bin/g++ -Wall -std=c++11 -m32 -g -gstabs   -I./include -I/Soft/team/linux/boost_1_53_0/32bit/include -I/Soft/team/linux/gtest-1.6.0/include -Itest/include   -c test/test_runner.cpp -o test/test_runner.o
    Traceback (most recent call last):
  File "/Home/me/repo/colout/colout.py", line 537, in <module>
    stdin_write( as_all, colortheme, themes[pattern].theme() )
  File "/Home/me/repo/colout/colout.py", line 505, in stdin_write
    map_write( sys.stdin, function, *args )
  File "/Home/me/repo/colout/colout.py", line 358, in map_write
    write( function(item, *args) )
  File "/Home/me/repo/colout/colout.py", line 328, in colortheme
    item = colorup(item, *args)
  File "/Home/me/repo/colout/colout.py", line 307, in colorup
    partial, end = colorout(text, match, end, group_colors[group-1], group_styles[group-1], group)
  File "/Home/me/repo/colout/colout.py", line 243, in colorout
    colored_text += colorin(text[start:end], color, style)
  File "/Home/me/repo/colout/colout.py", line 229, in colorin
    raise Exception('Unrecognized color %s' % color)
Exception: Unrecognized color Cpp

If everything is in C, it is OK though.
And if everything is in fr_FR, I don't get coloring because of keywords…

Option to run only when stdout is terminal

I'd like the command line switch that does the equivalent of --color=auto in grep and ls, which makes colout becomes no-op if the output isn't connected to a terminal.

This allows me to automatically enable colout for normal command line use without messing up my scripts.

Refactoring theme system

The current themes are handled as separated python scripts that import colout.
This is useless, as they are basically a way to chain calls to colorup.

Themes should just be scripts that builds a data structure of the form [{"regexp":"word","colors":"red,green","styles":"normal"},…].

The -r option is not handled properly

Calling colout with -r results in a "too few arguments" error. According to the documentation, -r and -h should be handled without the REGEX argument.

Print names in debug mode

In debug mode, print {red} where the ANSI red escaped sequence is inserted. Same for "none" and so on.

xml source

When I use -s xml option, the coloring of xml have tow issues:

  • a tag with several atributs have just the first line colored
  • the xml comment isn't colored

Uploading capture.png . . .

Long term idea : color with numerical expression

An interesting use case for me would be for example to color in red some part of log files depending on a numerical expression:

[...] duration=1.234 [...]
[...] duration=0.234 [...]
[...] duration=10.234 [...]

red when duration in [1;5[
bold red when duration in > 5
yellow when duration in [0.5;1[
green when duration in [0;0.5[
[...]

Multicolors

Add a "rainbow" color that cycle through colors.
Add a "random" color that choose a random one.

g++ theme: Unrecognized color Cpp

When using g++ theme, an exception is raised: "Unrecognized color Cpp".
It seems that the last colour entry in colout_g++.py provokes the error.

Rainbow is strange in my command line

There is a usage about Rainbow in http://nojhan.github.io/colout/ shows that, the "###"would be beautiful likes rainbow:
progress_Rainbow.png

But it strange in my commandline, screenshot is:
abc

What happens? Should I configure something?
Thanks!!

By the way, can I add the colout in alias? For example,add it with ls / cat / tail / head ...
If yes, how can I do?

IOError if next process in pipeline doesn't read all of colout's output

If the next process after colout in a pipeline exits without reading all of colout's stdout, e.g:

$ ls | colout . red | head -1

Then colout correctly prints one line of red output, but then crashes at:

Traceback (most recent call last):
File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/local/lib64/python2.6/site-packages/colout/colout.py", line 557, in
stdin_write( as_all, colorup, pattern, color, style, on_groups )
File "/usr/local/lib64/python2.6/site-packages/colout/colout.py", line 505, in stdin_write
map_write( sys.stdin, function, *args )
File "/usr/local/lib64/python2.6/site-packages/colout/colout.py", line 358, in map_write
write( function(item, *args) )
File "/usr/local/lib64/python2.6/site-packages/colout/colout.py", line 337, in write
sys.stdout.flush()
IOError: [Errno 32] Broken pipe

I guess one should handle these exceptions and simply exit cleanly?

Multi-line strings are highlighted incorrectly with Pygments

For example, in something like this:

colout -s Python < colout/colout.py

Multi-line strings don't get highlighted correctly; the first line is highlighted, but the subsequent lines are highlighted as though they were not in the middle of a string. (Examples: triple-quoted and multi-line docstrings, and some of the help strings in __args_parse__ which use a line continuation*.)

I presume that colout is providing Pygments the content line-by-line in such a way that Pygments doesn't know it should keep triple-quoted strings or strings with line continuation open.


* (Off topic.) In case you didn't know, inside an expression, having a string at the end of one line and a string at the start of the next with no operator between is semantically equivalent and I at least tend to prefer it as you can then indent the next line properly without getting surplus whitespace. Thus, instead of:

parser.add_argument("-g", "--groups", action="store_true",
        help="For color maps (random, rainbow), iterate over matching groups \
            in the pattern instead of over patterns")

I would do:

parser.add_argument("-g", "--groups", action="store_true",
        help="For color maps (random, rainbow), iterate over matching groups "
            "in the pattern instead of over patterns")

The bytecode has this as a single string literal. Tool support for this way (e.g. gettext) is good.

Encoding error when coloring each char

There are some encoding issues when coloring each character from a source, with the command colout "." rainbow, for instance.

In this case, accentued letters like "é" or "à" are displayed "�".

Handle resources directories

Permits to indicate where to search for themes/palettes.

Incidentally, add an explicit option to list available resources instead of having them printed in the help.

Alternative colors in output

Hey, I'm not sure if colout is capable of just highlighting a new output.. say we have

tail -f /var/log/apache2/error.log

after it updates another output, it should alternate to another colors. like group it. Do you think it's possible?

Add a way to reverse colormaps

Sometimes, one want to use a colormap in reverse order. For example with the scale special colormap.
Should we add an option to reverse (all the colormaps used in a single call) or should we automatically generate reverse colormaps (scale => r:scale) or someting else?

Bugs in __args_dirty__?

colout/colout/colout.py

Lines 687 to 698 in 3e0535d

if len(argv) == 5:
on_groups = bool(argv[4])
if len(argv) == 6:
as_colormap = bool(argv[5])
if len(argv) == 7:
as_theme = bool(argv[6])
if len(argv) == 8:
as_source = bool(argv[7])
if len(argv) == 9:
as_all = bool(argv[8])
if len(argv) == 10:
scale = bool(argv[9])

If len(argv) is == 5, then how can it be == 6,7,8... or anything else than 5?

Shouldn't there be a >= operator used in all ifs?

Also, what about rewriting that crappy if with try ... expect IndexError: pass?

Also,

return pattern, color, style, on_groups, as_colormap, as_theme, as_source, as_all, scale
looks pretty much like UnboundLocalError

I may try to rewrite it, but this function is To be used only when argparse is not available.
There is Python 3 shebang though, and argparse is part of Python 3.2 standard library... Why not just nuke it?

Python package

Please add a setup.py file to provide a python package.
Thank.

Config files

Permits a default configuration in files additionally to command lines arguments.
For instance for indicating directories where to find themes and palettes.

There should be a way to color a whole line that matches

I'm getting strange results when I use regexes like

"(.* (strikes|bashes|bites|slashes|stabs|kicks|punches) .*)" 

where the lines flow into each other as if their line terminators are missing. And also a line after the matching line is not colored since it flows into the now matched line.

Many other issues when I use these regexes too, disappearing letters.

So I was hoping I could use a simpler regex that only matches a word on the line, but with an argument that colors the whole matching line.

".* (strikes|bashes|bites|slashes|stabs|kicks|punches) .*"

Woul only color the matching word, but with an argument maybe it could color the whole line where the word matches?

Or perhaps I'm doing my regex wrong.

Allow a --themes-dir that is not on the default sys.path

I'd like to have a personal collection of themes, or have one shipped in a package with sources. At present, specifying a themes directory not on my default python module search path results in an error:

  ./colout/colout.py --themes-dir ~/_config/colout --r themes
Traceback (most recent call last):
  File "./colout/colout.py", line 985, in <module>
    load_themes( adir )
  File "./colout/colout.py", line 226, in load_themes
    context["themes"][name] = importlib.import_module(module)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'colout_llsd'

define entry point in setup.py

Please define an entry point where the script installs to.

entry_points={
        'console_scripts':
            ['colout = colout:main']
}

colout -t something: Choose a default translation file if no one is found

colout is a great software.

Although, there is a little glitch when no translation files are found. In this case, it would be nice to use a default translation file.

Traceback (most recent call last):
  File "/usr/local/bin/colout", line 537, in <module>
    stdin_write( as_all, colortheme, themes[pattern].theme() )
  File "/usr/local/bin/colout-bin/colout/colout_g++.py", line 12, in theme
    t = gettext.translation("gcc-"+gv)
  File "/usr/lib/python3.2/gettext.py", line 416, in translation
    raise IOError(ENOENT, 'No translation file found for domain', domain)
IOError: [Errno 2] No translation file found for domain: 'gcc-4.7'

Python traceback when compiling with cmake+make

I can not use colout :(

The command:

make -j 8 2>&1 | colout -t cmake | colout -t g++

The output:

make[3]: warning: jobserver unavailable: using -j1.  Add `+' to parent make rule.
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 842, in <module>
    write_all( as_all, sys.stdin, sys.stdout, colortheme, themes[pattern].theme() )
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 729, in write_all
    map_write( stream_in, stream_out, function, *args )
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 574, in map_write
    write( function(item, *args), stream_out )
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 536, in colortheme
    item = colorup(item, *args)
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 514, in colorup
    partial, end = colorout(text, match, end, group_colors[group-1], group_styles[group-1], group)
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 444, in colorout
    colored_text += colorin(text[start:end], color, style)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)

shortcuts/themes

Add shortcuts to color whole themes, like colout gcc to color the output of gcc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.