buba/buba/animations/charset.py

26 lines
778 B
Python

from time import sleep
from buba.bubaanimator import BubaAnimation
from buba.bubacmd import BubaCmd
class BubaCharset(BubaAnimation):
def __init__(self, buba: BubaCmd, single=None):
super().__init__(buba)
self.charset = bytes(range(256)).decode("CP437")
self.single = single
def run(self):
if self.single is not None:
while True:
self.render(self.single)
sleep(1)
else:
for page in range(16):
self.render(page)
sleep(5)
def render(self, page):
for row in range(4):
start = ((page + row) * 16) % 256
self.buba.simple_text(page=0, row=row, col=0, text=f"${start:02x}: {self.charset[start:start + 16]}")