Skip to content

Instantly share code, notes, and snippets.

@insom
Created April 28, 2023 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insom/9cc677a348db98530e2958e68d41c813 to your computer and use it in GitHub Desktop.
Save insom/9cc677a348db98530e2958e68d41c813 to your computer and use it in GitHub Desktop.
Render a UF2 file (from 100r) on the terminal.
#!/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