vtterm

Show a VT100 terminal with ANSI colors on a board’s display.

Terminal fits a grid of character cells to a display, reads escape codes from whatever you feed it, and draws the rows that changed. Use it two ways:

  • As the board’s own console: Console hands it to os.dupterm, so the REPL appears on the display.

  • As a terminal for another device: run joins it to a link (another board’s REPL over Bluetooth LE, a TCP socket, a UART).

Example

>>> from board_config import display_drv
>>> from vtterm import Terminal
>>> term = Terminal(display_drv)
>>> term.write(b"\x1b[1;32mhello\x1b[0m world\r\n")
class vtterm.Terminal(display, font_height=16, cols=None, rows=None, fg=7, bg=0, palette=None, hardware_scroll=None, scrollback=16384)[source]

Bases: object

A screen, its parser and its renderer, sized to a display.

Parameters:
  • display – A 16-bit display driver (board_config.display_drv).

  • font_height (int) – 8, 14 or 16; the font is 8 pixels wide.

  • cols (int) – Columns; default as many as fit.

  • rows (int) – Rows; default as many as fit.

  • fg (int) – Default foreground, an ANSI palette index.

  • bg (int) – Default background, an ANSI palette index.

  • palette (Palette) – 16-bit colors for the 256 ANSI indices.

  • hardware_scroll (bool) – Scroll with the display’s scroll registers; None (default) uses them when the driver has them.

  • scrollback (int) – Bytes to keep of rows that scrolled off the top, four per cell (a 40-column screen keeps about 100 rows in 16 KB). 0 keeps none.

screen

The grid.

Type:

Screen

parser

Reads bytes onto the grid.

Type:

Parser

renderer

Draws the grid.

Type:

Renderer

feed(data)[source]

Read data onto the grid without drawing.

render()[source]

Draw the rows that changed. Returns how many were drawn.

scroll_back(rows)[source]

Scroll the view back rows rows into the scrollback (negative goes forward) and draw it.

New output returns the view to the live screen.

write(data)[source]

Read data onto the grid and draw it.

answers()[source]

Return the bytes the terminal owes the other end (reports), or None.