From 17420be917de5054676448e92f5f19dea3aebce5 Mon Sep 17 00:00:00 2001 From: Scott Lawrence Date: Thu, 2 Apr 2015 10:34:51 -0400 Subject: [PATCH 1/4] fix for Issue #75: add the --themes-dir to the module import path --- colout/colout.py | 1 + 1 file changed, 1 insertion(+) diff --git a/colout/colout.py b/colout/colout.py index 2d232ba..c68c948 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -215,6 +215,7 @@ def load_themes( themes_dir): global context logging.debug("search for themes in: %s" % themes_dir) os.chdir( themes_dir ) + sys.path.append( themes_dir ) # load available themes for f in glob.iglob("colout_*.py"): From f03ed7a647803fe1e635cc267fd0e5354c5cad32 Mon Sep 17 00:00:00 2001 From: nojhan Date: Thu, 18 Aug 2016 20:54:50 +0200 Subject: [PATCH 2/4] Add remark about shell buffering --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 3cc48a6..fe270e8 100644 --- a/README.md +++ b/README.md @@ -286,3 +286,10 @@ 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 | qrep Y | colout Y`) 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 Y`. From fb9de000ed01a7b84fee24b702ea0802ba70ffe5 Mon Sep 17 00:00:00 2001 From: nojhan Date: Thu, 18 Aug 2016 21:11:33 +0200 Subject: [PATCH 3/4] Add a message for a common error fix #73 --- colout/colout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colout/colout.py b/colout/colout.py index c68c948..7d436db 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -1089,6 +1089,6 @@ if __name__ == "__main__": for var in context: print(var,context[var]) print(traceback.format_exc()) - logging.error("unknown color: %s" % e ) + logging.error("unknown color: %s (maybe you forgot to install python3-pygments?)" % e ) sys.exit( error_codes["UnknownColor"] ) From 01d1ab6b20bb375b0af38ffbe7d5eb33686bbab5 Mon Sep 17 00:00:00 2001 From: nojhan Date: Thu, 18 Aug 2016 21:18:58 +0200 Subject: [PATCH 4/4] Remove the dirty arg management, only keep argparse fix #70 --- colout/colout.py | 76 ++++-------------------------------------------- 1 file changed, 5 insertions(+), 71 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index 7d436db..a5744d9 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -17,6 +17,7 @@ import signal import string import hashlib import functools +import argparse # set the SIGPIPE handler to kill the program instead of # ending in a write error when a broken pipe occurs @@ -755,64 +756,7 @@ def colorgen(stream, pattern, color="red", style="normal", on_groups=False): # Command line tools # ###################### -def __args_dirty__(argv, usage=""): - """ - Roughly extract options from the command line arguments. - To be used only when argparse is not available. - - Returns a tuple of (pattern,color,style,on_stderr). - - >>> colout.__args_dirty__(["colout","pattern"],"usage") - ('pattern', 'red', 'normal', False) - >>> colout.__args_dirty__(["colout","pattern","colors","styles"],"usage") - ('pattern', 'colors', 'styles', False) - >>> colout.__args_dirty__(["colout","pattern","colors","styles","True"],"usage") - ('pattern', 'colors', 'styles', True) - """ - - # Use a dirty argument picker - # Check for bad usage or an help flag - if len(argv) < 2 \ - or len(argv) > 10 \ - or argv[1] == "--help" \ - or argv[1] == "-h": - print(usage+"\n") - print("Usage:", argv[0], " [] [] []") - print("\tAvailable colors:", " ".join(context["colors"])) - print("\tAvailable styles:", " ".join(context["styles"])) - print("Example:", argv[0], "'^(def)\s+(\w*).*$' blue,magenta italic,bold < colout.py") - sys.exit(1) - - assert(len(argv) >= 2) - # Get mandatory arguments - pattern = argv[1] - - # default values for optional args - color = "red" - style = "normal" - on_stderr = False - - if len(argv) >= 3: - color = argv[2] - if len(argv) >= 4: - style = argv[3] - 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]) - - return pattern, color, style, on_groups, as_colormap, as_theme, as_source, as_all, scale - - -def __args_parse__(argv, usage=""): +def _args_parse(argv, usage=""): """ Parse command line arguments with the argparse library. Returns a tuple of (pattern,color,style,on_stderr). @@ -923,19 +867,9 @@ if __name__ == "__main__": ##################### # Arguments parsing # ##################### - try: - import argparse - - # if argparse is not installed - except ImportError: - pattern, color, style, on_groups, as_colormap, as_theme, as_source, as_all, myscale \ - = __args_dirty__(sys.argv, usage) - - # if argparse is available - else: - pattern, color, style, on_groups, as_colormap, as_theme, as_source, as_all, myscale, \ - debug, resources, palettes_dirs, themes_dirs, default_colormap \ - = __args_parse__(sys.argv, usage) + pattern, color, style, on_groups, as_colormap, as_theme, as_source, as_all, myscale, \ + debug, resources, palettes_dirs, themes_dirs, default_colormap \ + = _args_parse(sys.argv, usage) if debug: lvl = logging.DEBUG