Last active
November 9, 2020 21:24
-
-
Save secoats/4a9817a6aa714c1ebce417a9b3698a43 to your computer and use it in GitHub Desktop.
Scan printout with automatic line overwrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Console print-out with automatic overwrite of negative results for scan tools and such. | |
# If you have multiple threads producing data, then you would probably need to create a dedicated worker thread for printing, | |
# with maybe a thread-safe queue supplying elements to print. | |
# Alternatively set prev_len to a constant value and truncate lines that are to long | |
# U+0A75 | |
# add padding according to length of last line | |
def print_fluid(text, last_len, ending): | |
print(text + (" " * last_len), end=ending) | |
return len(text) | |
data = [] | |
prev_len = 0 | |
# this loop would normally be some on-going scan or file parsing | |
for element in data: | |
condition = element.startswith("a") # some condition or function that determines whether the element matches | |
if condition: | |
prev_len = print_fluid("[+] " + element, prev_len, "\n") # positive result | |
else: | |
prev_len = print_fluid("[-] " + element, prev_len, "\r") # negative result | |
print("[*] Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment