Created
April 28, 2023 03:16
-
-
Save insom/9cc677a348db98530e2958e68d41c813 to your computer and use it in GitHub Desktop.
Render a UF2 file (from 100r) on the terminal.
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 | |
import sys | |
f = open(sys.argv[1], 'rb') | |
print(sys.argv[1]) | |
across = 0 | |
for q in sys.argv[2]: | |
c = ord(q) | |
f.seek(0, 0) | |
widths = f.read(256) | |
w = widths[c] | |
for i in range(c + 1): | |
first_set = f.read(32) | |
for i in range(16): | |
sys.stdout.write("\033[%dC" % across) | |
for (b, l) in ((first_set[i], 0), (first_set[i+16], 1)): | |
for x in range(8): | |
current = (l * 8 + x) | |
if current < w: | |
sys.stdout.write(((b >> (7 - x)) & 1) and "#" or " ") | |
sys.stdout.write("\n") | |
across += w | |
sys.stdout.write("\033[16A") | |
sys.stdout.write("\033[16B") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment