Allow big group matching for "scale" special color
When matching a group with "scale", filter out everything that does not seem to be necessary to interpret the string as a number this permits to transform "[95%]" to "95" before number conversion, and thus allows to color a group larger than the matched number Update the cmake theme accordingly.
This commit is contained in:
parent
94e9d04866
commit
f30838cc57
3 changed files with 32 additions and 7 deletions
15
README.md
15
README.md
|
|
@ -35,9 +35,14 @@ the 256 color escape sequences).
|
|||
`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.
|
||||
|
||||
`scale` (8 colors) and `Scale` (36 colors) will parse the matching text as
|
||||
a decimal number and apply the rainbow colormap according to its position
|
||||
on the scale defined by the `-l` option (see below, "0,100" by default).
|
||||
`scale` (8 colors) and `Scale` (36 colors) will parse the numbers characters in
|
||||
the matching text as a decimal number and apply the rainbow colormap according
|
||||
to its position on the scale defined by the `-l` option (see below, "0,100" by
|
||||
default).
|
||||
|
||||
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
|
||||
syntax-coloring "lexer" as a color (for example: "Cpp", "ruby", "xml+django", etc.).
|
||||
|
|
@ -219,6 +224,10 @@ Don't use nested groups or colout will duplicate the corresponding input text wi
|
|||
* 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`
|
||||
|
||||
|
||||
### Bash alias
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import math
|
|||
import importlib
|
||||
import logging
|
||||
import signal
|
||||
import string
|
||||
|
||||
# set the SIGPIPE handler to kill the program instead of
|
||||
# ending in a write error when a broken pipe occurs
|
||||
|
|
@ -326,11 +327,21 @@ def colorin(text, color="red", style="normal"):
|
|||
colormap_idx = 0
|
||||
|
||||
elif color.lower() == "scale": # "scale" or "Scale"
|
||||
|
||||
# filter out everything that does not seem to be necessary to interpret the string as a number
|
||||
# this permits to transform "[ 95%]" to "95" before number conversion,
|
||||
# and thus allows to color a group larger than the matched number
|
||||
chars_in_numbers = "-+.,e"
|
||||
allowed = string.digits + chars_in_numbers
|
||||
nb = "".join([i for i in filter(allowed.__contains__, text)])
|
||||
|
||||
# interpret as decimal
|
||||
try:
|
||||
# babel is a specialized module
|
||||
import babel.numbers as bn
|
||||
f = float(bn.parse_decimal(text))
|
||||
f = float(bn.parse_decimal(nb))
|
||||
except ImportError:
|
||||
f = float(text)
|
||||
f = float(nb)
|
||||
|
||||
# if out of scale, do not color
|
||||
if f < scale[0] or f > scale[1]:
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ def theme():
|
|||
performing="cyan"
|
||||
# actions performed in green
|
||||
performed="green"
|
||||
# actions taking an unknown time
|
||||
untimed="blue"
|
||||
|
||||
return [
|
||||
# Configure...
|
||||
|
|
@ -24,16 +26,19 @@ def theme():
|
|||
performing, "normal,bold" ],
|
||||
# Link
|
||||
[ "^(Linking .* )(library|executable) (.*/)*(.+(\.[aso]+)*)$",
|
||||
performing, "normal,normal,bold" ],
|
||||
untimed, "normal,normal,bold" ],
|
||||
# [percent] Built
|
||||
[ "^\[\s*[0-9]+%\]\s(Built target)(\s.*)$",
|
||||
performed, "normal,bold" ],
|
||||
# [percent] Building
|
||||
[ "^\[\s*[0-9]+%\]\s(Building \w* object)(\s+.*/)([-\w]+.c.*)(.o)$",
|
||||
performing, "normal,normal,bold,normal"],
|
||||
# [percent] Generating
|
||||
[ "^\[\s*[0-9]+%\]\s(Generating)(\s+.*)$",
|
||||
performing, "normal,bold"],
|
||||
# make errors
|
||||
[ "make\[[0-9]+\].*", "yellow"],
|
||||
[ "(make: \*\*\* \[.+\] )(.* [0-9]+)", "red", "normal,bold"],
|
||||
# progress percentage
|
||||
[ "^\[\s*([0-9]+)%\]","Scale" ]
|
||||
[ "^(\[\s*[0-9]+%\])","Scale" ]
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue