Dynamic warning if babel or pygments are not installed
This commit is contained in:
parent
b9176eab52
commit
796246e789
2 changed files with 23 additions and 7 deletions
|
|
@ -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
|
||||
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.).
|
||||
|
||||
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
|
||||
(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 have a list of all colors, styles, special colormaps, themes, palettes and lexers,
|
||||
|
|
|
|||
|
|
@ -666,10 +666,17 @@ def __args_parse__(argv, usage=""):
|
|||
parser.add_argument("pattern", metavar="REGEX", type=str, nargs=1,
|
||||
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='?',
|
||||
default="red",
|
||||
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='?',
|
||||
default="bold",
|
||||
|
|
@ -682,9 +689,18 @@ def __args_parse__(argv, usage=""):
|
|||
parser.add_argument("-c", "--colormap", action="store_true",
|
||||
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",
|
||||
help="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")
|
||||
help="When using the 'scale' colormap, parse matches as decimal numbers \
|
||||
and apply the rainbow colormap linearly between the given SCALE=min,max" + babel_warn)
|
||||
|
||||
parser.add_argument("-a", "--all", action="store_true",
|
||||
help="Color the whole input at once instead of line per line \
|
||||
|
|
@ -815,9 +831,9 @@ if __name__ == "__main__":
|
|||
print("NO COLORMAPS")
|
||||
|
||||
if len(lexers) > 0:
|
||||
print("LEXERS: %s" % ", ".join(lexers) )
|
||||
print("SYNTAX COLORING: %s" % ", ".join(lexers) )
|
||||
else:
|
||||
print("NO LEXER")
|
||||
print("NO SYNTAX COLORING (check that python3-pygments is installed)")
|
||||
|
||||
sys.exit(0) # not an error, we asked for help
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue