Last active
October 2, 2023 02:58
-
-
Save anecdata/d208b41828a2103b3039e4ccaf5d8cf3 to your computer and use it in GitHub Desktop.
terminalio.Terminal with color
This file contains hidden or 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
# SPDX-FileCopyrightText: 2023 anecdata | |
# | |
# SPDX-License-Identifier: Unlicense | |
# terminalio.FONT.bitmap is 2-color | |
# changing a palette color changes every use of that palette | |
# but there's got to be a better way... | |
import time | |
import random | |
import sys | |
import board | |
import displayio | |
import terminalio | |
STRLEN = 39 | |
CHARS = "0123456789ABCDEF" | |
def get_logterm(color): | |
fontx, fonty = terminalio.FONT.get_bounding_box() | |
palette = displayio.Palette(2) | |
palette[0] = 0x000000 | |
palette[1] = color | |
palette.make_transparent(0) | |
logbox = displayio.TileGrid(terminalio.FONT.bitmap, | |
x=0, | |
y=0, | |
width=display.width // fontx, | |
height=display.height // fonty, | |
tile_width=fontx, | |
tile_height=fonty, | |
pixel_shader=palette) | |
return logbox, terminalio.Terminal(logbox, terminalio.FONT) | |
display = board.DISPLAY # or equivalent external display library | |
splash = displayio.Group() | |
w_logbox, w_logterm = get_logterm(0xffffff) | |
r_logbox, r_logterm = get_logterm(0xff0000) | |
g_logbox, g_logterm = get_logterm(0x00ff00) | |
b_logbox, b_logterm = get_logterm(0x0000ff) | |
splash.append(w_logbox) | |
splash.append(r_logbox) | |
splash.append(g_logbox) | |
splash.append(b_logbox) | |
display.show(splash) | |
print("\033["+"31m"+"Hello Serial!"+"\033["+"0m", file=sys.stdout) # serial console | |
print("\r\nHello displayio!", file=w_logterm, end="") # displayio | |
terms = (w_logterm, r_logterm, g_logterm, b_logterm) | |
while True: | |
term = random.choice(terms) | |
for this_term in terms: | |
if this_term is term: | |
print(f"\r\n{"".join(random.choice(CHARS) for _ in range(STRLEN))}", file=this_term, end="") # displayio | |
else: | |
print(f"\r\n", file=this_term, end="") # displayio | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
single-color: https://gist.github.com/anecdata/0e426cc9d150c078f7f0b276afa6ff57