From 5f07ea15f2b18e238550ab4d50279a427806e7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Mon, 9 Sep 2024 17:15:04 +0200 Subject: [PATCH] utils.astring: Add ^c, ^!p and ^]104 to skip chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit these are sometimes generated by kernel, ignore them. Signed-off-by: Lukáš Doktor Signed-off-by: Sebastian Mitterle --- aexpect/utils/astring.py | 2 +- tests/test_utils.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/aexpect/utils/astring.py b/aexpect/utils/astring.py index 4d4e2a9..34936ff 100644 --- a/aexpect/utils/astring.py +++ b/aexpect/utils/astring.py @@ -37,7 +37,7 @@ def strip_console_codes(output, custom_codes=None): output = f"\x1b[m{output}" console_codes = "^%[G@8]|^\\[[@A-HJ-MPXa-hl-nqrsu\\`]" console_codes += "|^\\[[\\d;]+[HJKgqnrm]|^#8|^\\([B0UK]|^\\)" - console_codes += "|^\\[\\?2004[lh]" + console_codes += "|^\\[\\?2004[lh]|^c|^\\[!p|^\\]\\d+" if custom_codes is not None and custom_codes not in console_codes: console_codes += f"|{custom_codes}" while index < len(output): diff --git a/tests/test_utils.py b/tests/test_utils.py index c3bdb18..6e9c987 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -32,6 +32,8 @@ def test_strip_console_codes(self): strip("\x1bskip-full-text")) self.assertEqual("ignores last", strip("ignores last\x1bbad")) + self.assertEqual("skips c [!p and ]104", + strip("skips\x1bc c \x1b[!p[!p and ]104\x1b]104")) self.assertRaisesRegex(ValueError, "only is not included", strip, "ignores\x1bonly\x1blast\x1bbad") self.assertRaisesRegex(ValueError, "invalid-prefix.*included", strip,