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
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -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: