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:
Johann Dreo 2013-09-25 00:04:20 +02:00
commit f30838cc57
3 changed files with 32 additions and 7 deletions

View file

@ -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]:

View file

@ -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" ]
]