From ee27439a7c63e9ccda5cde7cac99a3f86f1b139a Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Sun, 21 Jul 2019 23:00:35 +1000 Subject: [PATCH] tools: Ignore unfinished ascii escape codes. - Ignore if the code doesn't end in 'm'. --- eris/termstr.py | 5 ++++- tests/termstr_test.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/eris/termstr.py b/eris/termstr.py index eb12555..ea1560b 100644 --- a/eris/termstr.py +++ b/eris/termstr.py @@ -170,7 +170,10 @@ class TermStr(collections.UserString): end_index = part.index("K") codes = [] else: - end_index = part.index("m") + try: + end_index = part.index("m") + except ValueError: + continue codes = part[1:end_index].split(";") previous_code = None for index, code in enumerate(codes): diff --git a/tests/termstr_test.py b/tests/termstr_test.py index 6f05df0..522f7e6 100755 --- a/tests/termstr_test.py +++ b/tests/termstr_test.py @@ -159,6 +159,9 @@ class TermStrTests(unittest.TestCase): termstr.TermStr("foo").fg_color(13)) self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[105mfoo"), termstr.TermStr("foo").bg_color(13)) + self.assertEqual(TermStr.from_term(eris.terminal.ESC + "(B" + + eris.terminal.ESC + "[mfoo"), + termstr.TermStr("foo")) if __name__ == "__main__":