Created
December 3, 2021 16:20
-
-
Save rsbohn/5799fb5c804d967d55fb5403b4db434e to your computer and use it in GitHub Desktop.
terminalio demo
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
# SPDX-FileCopyrightText: Copyright (c) 2021 Randall Bohn (dexter) | |
# | |
# SPDX-License-Identifier: MIT | |
""" | |
Demonstrate usage of the terminalio module. | |
The module provides a VT100 emulation within a displayo.TileGrid. | |
A good reference for VT100 "escape" codes is found at | |
https://www.csie.ntu.edu.tw/~r92094/c++/VT100.html | |
""" | |
import random | |
import time | |
import board | |
import displayio | |
import terminalio | |
display = board.DISPLAY | |
splash = displayio.Group() | |
display.show(splash) | |
palette = displayio.Palette(2) | |
palette[0]=0x220000 | |
palette[1]=0x00FFFF | |
ROWS=12 | |
COLS=40 | |
w,h = terminalio.FONT.get_bounding_box() | |
termgrid = displayio.TileGrid(terminalio.FONT.bitmap, pixel_shader=palette, y=20, | |
width=COLS, height=ROWS, | |
tile_width=w, tile_height=h) | |
splash.append(termgrid) | |
count = 20 | |
term = terminalio.Terminal(termgrid, terminalio.FONT) | |
def world_seed(n): | |
"""For entertainment purposes only.""" | |
letters = "AEIOUMRFCV" | |
word = [random.choice(letters) for _ in range(n)] | |
return "".join(word) | |
term.write(f"Terminal {COLS}x{ROWS}.\r\n") | |
term.write(f"{COLS*w}x{ROWS*h} pixels.\r\n") | |
term.write(f"VT100 protocol.\r\n") | |
term.write(f"Both carriage return and line feed are required.\r\n") | |
while True: | |
term.write(f"Your world seed is:\r\n") | |
for _ in range(10): | |
term.write(world_seed(12)+" ") | |
term.write("\r\n") | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment