diff --git a/eris/termstr.py b/eris/termstr.py index bd8f270..0087789 100644 --- a/eris/termstr.py +++ b/eris/termstr.py @@ -166,33 +166,38 @@ class TermStr(collections.UserString): is_bold, is_italic, is_underlined = False, False, False result_parts = [parts[0]] for part in parts[1:]: - try: - end_index = part.index("m") - except ValueError: - end_index = 0 - if part[:2] == terminal.normal or part[:3] == "[0m": # Normal - is_bold, is_italic, is_underlined = False, False, False - fg_color, bg_color = None, None - elif part[:3] == terminal.bold: - is_bold = True - elif part[:3] == terminal.italic: - is_italic = True - elif part[:3] == terminal.underline: - is_underlined = True - elif end_index == 3 and part.startswith("[3"): # 8 foreground color - fg_color = int(part[2]) - elif end_index == 3 and part.startswith("[4"): # 8 background color - bg_color = int(part[2]) - elif part[:6] == "[38;5;": # simple foreground color - fg_color = int(part[6:end_index]) - elif part[:6] == "[48;5;": # simple background color - bg_color = int(part[6:end_index]) - elif part[:6] == "[38;2;": # rgb foreground color - fg_color = tuple(int(component) - for component in part[6:end_index].split(";")) - elif part[:6] == "[48;2;": # rgb background color - bg_color = tuple(int(component) - for component in part[6:end_index].split(";")) + end_index = part.index("m") + codes = part[1:end_index].split(";") + previous_code = None + for index, code in enumerate(codes): + if code in ["", "0"]: # Normal + is_bold, is_italic, is_underlined = False, False, False + fg_color, bg_color = None, None + elif code == "1": # bold + is_bold = True + elif code == "3": # italic + is_italic = True + elif code == "4": # underline + is_underlined = True + elif len(code) == 2 and code.startswith("3"): # 8 fg color + fg_color = int(code[1]) + elif len(code) == 2 and code.startswith("4"): # 8 bg color + bg_color = int(code[1]) + elif code == "5" and previous_code == "38": # simple fg color + fg_color = int(codes[index+1]) + codes[index+1:index+2] = [] + elif code == "5" and previous_code == "48": # simple bg color + bg_color = int(codes[index+1]) + codes[index+1:index+2] = [] + elif code == "2" and previous_code == "38": # rgb fg color + fg_color = tuple(int(component) + for component in codes[index+1:index+4]) + codes[index+1:index+4] = [] + elif code == "2" and previous_code == "48": # rgb bg color + bg_color = tuple(int(component) + for component in codes[index+1:index+4]) + codes[index+1:index+4] = [] + previous_code = code result_parts.append(cls(part[end_index+1:], CharStyle(fg_color, bg_color, is_bold, is_italic, is_underlined))) diff --git a/eris/tools.toml b/eris/tools.toml index 97ceab5..00199ac 100644 --- a/eris/tools.toml +++ b/eris/tools.toml @@ -64,7 +64,8 @@ tools_for_extensions = [ [pylint] dependencies = ["pip/pylint"] url = "https://www.pylint.org/" - command = "python3.7 -m pylint --errors-only" + command = "python3.7 -m pylint -f colorized --errors-only" + has_color = true [python_modulefinder] dependencies = [] diff --git a/tests/golden-files/results/pylint-hi3_py b/tests/golden-files/results/pylint-hi3_py index e69de29..327aa11 100644 --- a/tests/golden-files/results/pylint-hi3_py +++ b/tests/golden-files/results/pylint-hi3_py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/termstr_test.py b/tests/termstr_test.py index 4588247..077b321 100755 --- a/tests/termstr_test.py +++ b/tests/termstr_test.py @@ -149,6 +149,8 @@ class TermStrTests(unittest.TestCase): eris.terminal.ESC + "[0mbar"), termstr.TermStr("foo").bg_color(5) + termstr.TermStr("bar")) + self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[1;3mfoo"), + termstr.TermStr("foo").bold().italic()) if __name__ == "__main__":