Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter_print to support filtering prints #64

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)