Terminal Graphics #
The terminalio.Terminal class implements a traditional 'terminal' with VT100 control codes. It does this by giving you a stream you can print to. It converts the stream of characters into a tilegrid using the bitmap font. It will wrap lines if necessary. Unfortunately it only supports a single color at a time. Multi-colored text isn't supported.
import terminalio
import displayio
# size of each font glyph (this is a monospaced font)
fontx, fonty = terminalio.FONT.get_bounding_box()
# adjust palette if desired
plain_palette = displayio.Palette(2)
plain_palette[0] = 0x000000
plain_palette[1] = 0x33ff33
# create grid using the font
# width and height in tiles
# x and y in pixels
pgrid = 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=plain_palette)
# terminal attached to the tilegrid
ptermx = terminalio.Terminal(pgrid, terminalio.FONT)
# add to the screen
display.root_group.append(pgrid)
Print to the terminal with print:
# with newline
print("some text", file=ptermx, end="\r\n")
# without newline
print("some text", file=ptermx, end="")