Dynamic warning if babel or pygments are not installed

This commit is contained in:
Johann Dreo 2014-02-10 21:05:21 +01:00
commit 796246e789
2 changed files with 23 additions and 7 deletions

View file

@ -44,7 +44,7 @@ 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 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. this special color on a large group, while interpreting only its numerical part.
If the python-pygments library is installed, you can use the name of a If the python3-pygments library is installed, you can use the name of a
syntax-coloring "lexer" as a color (for example: "Cpp", "ruby", "xml+django", etc.). 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 If GIMP palettes files (*.gpl) are available, you can also use their names as a
@ -58,7 +58,7 @@ 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 `colout` comes with some predefined themes to rapidly color well-known outputs
(see the `-t` switch below). (see the `-t` switch below).
If the python-pygments library is available, `colout` can be used as an interface If the python3-pygments library is available, `colout` can be used as an interface
to it (see also the `-s` switch below). to it (see also the `-s` switch below).
To have a list of all colors, styles, special colormaps, themes, palettes and lexers, To have a list of all colors, styles, special colormaps, themes, palettes and lexers,

View file

@ -666,10 +666,17 @@ def __args_parse__(argv, usage=""):
parser.add_argument("pattern", metavar="REGEX", type=str, nargs=1, parser.add_argument("pattern", metavar="REGEX", type=str, nargs=1,
help="A regular expression") help="A regular expression")
pygments_warn=" You can also use a language name to activate syntax coloring (see `-r all` for a list)."
try:
import pygments
except ImportError:
pygments_warn=" (WARNING: python3-pygments is not available, \
install it if you want to be able to use syntax coloring)"
parser.add_argument("color", metavar="COLOR", type=str, nargs='?', parser.add_argument("color", metavar="COLOR", type=str, nargs='?',
default="red", default="red",
help="A number in [0…255], a color name, a colormap name, \ help="A number in [0…255], a color name, a colormap name, \
a palette or a comma-separated list of those values.") a palette or a comma-separated list of those values."+pygments_warn)
parser.add_argument("style", metavar="STYLE", type=str, nargs='?', parser.add_argument("style", metavar="STYLE", type=str, nargs='?',
default="bold", default="bold",
@ -682,9 +689,18 @@ def __args_parse__(argv, usage=""):
parser.add_argument("-c", "--colormap", action="store_true", parser.add_argument("-c", "--colormap", action="store_true",
help="Use the given colors as a colormap (cycle the colors at each match)") help="Use the given colors as a colormap (cycle the colors at each match)")
babel_warn=" (numbers will be parsed according to your locale)"
try:
# babel is a specialized module
import babel.numbers
except ImportError:
babel_warn=" (WARNING: python3-babel is not available, install it \
if you want to be able to parse numbers according to your locale)"
parser.add_argument("-l", "--scale", parser.add_argument("-l", "--scale",
help="When using the 'scale' colormap, parse matches as decimal numbers (taking your locale into account) \ help="When using the 'scale' colormap, parse matches as decimal numbers \
and apply the rainbow colormap linearly between the given SCALE=min,max") and apply the rainbow colormap linearly between the given SCALE=min,max" + babel_warn)
parser.add_argument("-a", "--all", action="store_true", parser.add_argument("-a", "--all", action="store_true",
help="Color the whole input at once instead of line per line \ help="Color the whole input at once instead of line per line \
@ -815,9 +831,9 @@ if __name__ == "__main__":
print("NO COLORMAPS") print("NO COLORMAPS")
if len(lexers) > 0: if len(lexers) > 0:
print("LEXERS: %s" % ", ".join(lexers) ) print("SYNTAX COLORING: %s" % ", ".join(lexers) )
else: else:
print("NO LEXER") print("NO SYNTAX COLORING (check that python3-pygments is installed)")
sys.exit(0) # not an error, we asked for help sys.exit(0) # not an error, we asked for help