From d1867f61ab6748180611caa45d8c68201d64c79a Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Sun, 21 Jul 2019 21:51:38 +1000 Subject: [PATCH] tools: Enable color from gcc. --- eris/termstr.py | 14 +++++++++----- eris/tools.toml | 6 ++++-- tests/golden-files/results/c_syntax_gcc-hello_c | 1 + .../golden-files/results/cpp_syntax_gcc-hello_cpp | 1 + tests/termstr_test.py | 4 ++++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/eris/termstr.py b/eris/termstr.py index 0087789..c83c9fe 100644 --- a/eris/termstr.py +++ b/eris/termstr.py @@ -166,18 +166,22 @@ class TermStr(collections.UserString): is_bold, is_italic, is_underlined = False, False, False result_parts = [parts[0]] for part in parts[1:]: - end_index = part.index("m") - codes = part[1:end_index].split(";") + if part.startswith("[K"): + end_index = part.index("K") + codes = [] + else: + 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 + elif code in ["01", "1"]: # bold is_bold = True - elif code == "3": # italic + elif code in ["03", "3"]: # italic is_italic = True - elif code == "4": # underline + elif code in ["04", "4"]: # underline is_underlined = True elif len(code) == 2 and code.startswith("3"): # 8 fg color fg_color = int(code[1]) diff --git a/eris/tools.toml b/eris/tools.toml index 00199ac..10caf36 100644 --- a/eris/tools.toml +++ b/eris/tools.toml @@ -202,12 +202,14 @@ tools_for_extensions = [ [c_syntax_gcc] dependencies = ["gcc", "g++"] url = "https://gcc.gnu.org/" - command = "gcc -fsyntax-only" + command = "gcc -fsyntax-only -fdiagnostics-color=always" + has_color = true [cpp_syntax_gcc] dependencies = ["gcc", "g++"] url = "https://gcc.gnu.org/" - command = "gcc -fsyntax-only" + command = "gcc -fsyntax-only -fdiagnostics-color=always" + has_color = true [php7_syntax] dependencies = ["php7.2-cli"] diff --git a/tests/golden-files/results/c_syntax_gcc-hello_c b/tests/golden-files/results/c_syntax_gcc-hello_c index e69de29..327aa11 100644 --- a/tests/golden-files/results/c_syntax_gcc-hello_c +++ b/tests/golden-files/results/c_syntax_gcc-hello_c @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/golden-files/results/cpp_syntax_gcc-hello_cpp b/tests/golden-files/results/cpp_syntax_gcc-hello_cpp index e69de29..327aa11 100644 --- a/tests/golden-files/results/cpp_syntax_gcc-hello_cpp +++ b/tests/golden-files/results/cpp_syntax_gcc-hello_cpp @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/termstr_test.py b/tests/termstr_test.py index 077b321..fe49f64 100755 --- a/tests/termstr_test.py +++ b/tests/termstr_test.py @@ -151,6 +151,10 @@ class TermStrTests(unittest.TestCase): termstr.TermStr("bar")) self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[1;3mfoo"), termstr.TermStr("foo").bold().italic()) + self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[01mfoo"), + termstr.TermStr("foo").bold()) + self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[Kfoo"), + termstr.TermStr("foo")) if __name__ == "__main__":