vtterm.console
Put the board’s REPL on a Terminal with os.dupterm.
Console is the stream os.dupterm reads from and writes to. What the
REPL prints is drawn on the display; what you type reaches the REPL from a
key source you give it (KeyEvents, or anything with
a read() that returns bytes) or from bytes you Console.push. The USB
or serial REPL keeps working beside it.
The console does what a tty does for a terminal: a bare \n starts its
new line at column 0, so print on the unix port lines up.
Drawing is paced: while output streams, the display is redrawn at most every
interval_ms, and everything left over is drawn the next time the REPL
asks for input.
Example
>>> from board_config import display_drv
>>> from vtterm import Terminal
>>> from vtterm.console import Console
>>> console = Console(Terminal(display_drv))
>>> console.attach()
- class vtterm.console.Console(terminal, keys=None, interval_ms=40, idle_ms=5)[source]
Bases:
IOBaseA terminal as an
os.duptermstream.- Parameters:
terminal (Terminal) – Where the REPL’s output is drawn.
keys – A key source with
read()returning bytes orNone, polled whenever the REPL looks for input. Optional.interval_ms (int) – Shortest time between redraws while output streams.
idle_ms (int) – How long
readwaits when there’s nothing to read, so a REPL that polls in a loop (the unix port) doesn’t spin.
- attach(index=0)[source]
Hand this console to
os.duptermslotindex.- Raises:
OSError – If another stream (WebREPL, the BLE REPL) holds the slot.
- push(data)[source]
Queue
dataas typed input and tell the REPL it’s there.Ctrl-C in
datainterrupts a running program, as it does over USB, on ports withos.dupterm_notify.