Skip to content

Commit

Permalink
Add filter_print to support filtering prints
Browse files Browse the repository at this point in the history
  • Loading branch information
nitanmarcel authored and trufae committed Sep 29, 2024
1 parent bb80d4c commit bccc774
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions r2ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit bccc774

Please sign in to comment.