From d0ef6abdc6010e0cc99833126d696842eaa6380b Mon Sep 17 00:00:00 2001
From: Philippe Daouadi
Date: Fri, 25 Apr 2014 21:39:58 +0200
Subject: [PATCH 1/4] bugfix: start scale at right color
---
colout/colout.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/colout/colout.py b/colout/colout.py
index 293ed2c..3d3ebc0 100755
--- a/colout/colout.py
+++ b/colout/colout.py
@@ -391,7 +391,7 @@ def color_scale( name, text ):
# normalize and scale over the nb of colors in cmap
colormap = context["colormaps"][name]
- i = int( math.ceil( (f - context["scale"][0]) / (context["scale"][1]-context["scale"][0]) * len(colormap) ) ) - 1
+ i = int( math.ceil( (f - context["scale"][0]) / (context["scale"][1]-context["scale"][0]) * (len(colormap)-1) ) )
color = colormap[i]
# infer mode from the color in the colormap
From 1f9125af88ad9d13a7de6f972032dd810da300d6 Mon Sep 17 00:00:00 2001
From: Philippe Daouadi
Date: Fri, 25 Apr 2014 21:42:08 +0200
Subject: [PATCH 2/4] bugfix: crash when using fractions
---
colout/colout.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/colout/colout.py b/colout/colout.py
index 3d3ebc0..17ef20f 100755
--- a/colout/colout.py
+++ b/colout/colout.py
@@ -377,7 +377,7 @@ def color_scale( name, text ):
import babel.numbers as bn
try:
f = float(bn.parse_decimal(nb))
- except NumberFormatError:
+ except bn.NumberFormatError:
f = eval(nb) # Note: in python2, `eval(2/3)` would produce `0`, in python3 `0.666`
except ImportError:
try:
From d437e463648d194763ae0e90440e8a37cc0dfbdf Mon Sep 17 00:00:00 2001
From: Philippe Daouadi
Date: Fri, 25 Apr 2014 21:46:49 +0200
Subject: [PATCH 3/4] Make cmake colouring work with fractions
---
colout/colout.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/colout/colout.py b/colout/colout.py
index 17ef20f..ede0d37 100755
--- a/colout/colout.py
+++ b/colout/colout.py
@@ -372,26 +372,33 @@ def color_scale( name, text ):
# if not, use python itself,
# if thoses fails, try to `eval` the string
# (this allow strings like "1/2+0.9*2")
+ f = None
try:
# babel is a specialized module
import babel.numbers as bn
try:
f = float(bn.parse_decimal(nb))
except bn.NumberFormatError:
- f = eval(nb) # Note: in python2, `eval(2/3)` would produce `0`, in python3 `0.666`
+ pass
except ImportError:
try:
f = float(nb)
except ValueError:
- f = eval(nb)
+ pass
+ if f is not None:
+ # normalize with scale if it's a number
+ f = (f - context["scale"][0]) / (context["scale"][1]-context["scale"][0])
+ else:
+ # interpret as float between 0 and 1 otherwise
+ f = eval(nb)
# if out of scale, do not color
- if f < context["scale"][0] or f > context["scale"][1]:
+ if f < 0 or f > 1:
return None
# normalize and scale over the nb of colors in cmap
colormap = context["colormaps"][name]
- i = int( math.ceil( (f - context["scale"][0]) / (context["scale"][1]-context["scale"][0]) * (len(colormap)-1) ) )
+ i = int( math.ceil( f * (len(colormap)-1) ) )
color = colormap[i]
# infer mode from the color in the colormap
From 4cdf3e609df037d313e74c333197d8ea53edc6cb Mon Sep 17 00:00:00 2001
From: nojhan
Date: Sat, 21 Jun 2014 11:30:32 +0200
Subject: [PATCH 4/4] bugfix: debug variable corret declaration
---
colout/colout.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/colout/colout.py b/colout/colout.py
index 94b06ba..5973fc9 100755
--- a/colout/colout.py
+++ b/colout/colout.py
@@ -28,6 +28,7 @@ signal.signal( signal.SIGPIPE, signal.SIG_DFL )
###############################################################################
context = {}
+debug = False
# Available styles
context["styles"] = {
@@ -615,6 +616,7 @@ def colorup(text, pattern, color="red", style="normal", on_groups=False):
'\x1b[1;34mF\x1b[0m\x1b[3;34maites\x1b[0m \x1b[1;34mC\x1b[0m\x1b[3;34mhier\x1b[0m la Vache'
"""
global context
+ global debug
if not debug:
regex = re.compile(pattern)
@@ -906,7 +908,6 @@ def write_all( as_all, stream_in, stream_out, function, *args ):
if __name__ == "__main__":
- global debug
error_codes = {"UnknownColor":1, "DuplicatedPalette":2}
usage = "A regular expression based formatter that color up an arbitrary text stream."