From bccc7748c375cb9988786d599d6d5706e4d51269 Mon Sep 17 00:00:00 2001 From: Marcel Alexandru Nitan Date: Sun, 29 Sep 2024 14:54:32 +0300 Subject: [PATCH] Add filter_print to support filtering prints --- r2ai/utils.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/r2ai/utils.py b/r2ai/utils.py index 05849af4..f041ca53 100644 --- a/r2ai/utils.py +++ b/r2ai/utils.py @@ -40,3 +40,30 @@ def syscmdstr(cmd): process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) output, error = process.communicate() return output.decode().strip() + + +def filter_print(*args, **kwargs): + _args = [] + filter = None + if "filter" in kwargs: + filter = kwargs["filter"] + del kwargs["filter"] + for a in args: + new = "" + lines = str(a).splitlines() + if len(lines) > 1: + for line in lines: + if filter is not None: + if filter in line: + new += line + "\n" + else: + new += line + "\n" + else: + if filter is not None: + if filter in str(a): + new += str(a) + else: + new += str(a) + _args.append(new) + + print(*_args, **kwargs) \ No newline at end of file