Skip to content
Snippets Groups Projects
Commit 86173182 authored by Sebastien Luttringer's avatar Sebastien Luttringer
Browse files

fix bug of color substituion

a bug occur with string like "#l##c#R#R#".
This is due to order of processing colors.
Now use re.sub
parent a340c26a
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ Install Systems Printer module
import sys
import os
import re
import installsystems
NOCOLOR = False
......@@ -48,11 +49,8 @@ def out(message="", fd=sys.stdout, endl=os.linesep, flush=True):
Print message colorised in fd ended by endl
'''
# color subsitution
for c in COLOR:
if not fd.isatty() or NOCOLOR:
message = message.replace("#%s#" % c, "")
else:
message = message.replace("#%s#" % c, COLOR[c])
color_pattern = "#(%s)#" % "|".join(COLOR)
message = re.sub(color_pattern, lambda obj: COLOR[obj.group(1)], message)
# convert unicode into str before write
# this can cause issue on python 2.6
if type(message) == unicode:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment