vtterm.session

Join a Terminal to another device’s console.

run is an asyncio loop: bytes from the link are drawn, and key presses and the terminal’s reports go back down the link. A link is anything with async read(n) and write(data): a bledev.nus.Link from bledev.repl.connect, or an asyncio stream from a TCP socket or a UART.

Example

>>> import asyncio, bledev.repl
>>> from vtterm.session import run
>>> link = await bledev.repl.connect(ble, "password", name="mpy-repl")
>>> await run(term, link, keys)
async vtterm.session.run(terminal, link, keys=None, poll_ms=20, stop=None)[source]

Show the link’s output and send it keys until it closes or stop is set.

Parameters:
  • terminal (Terminal) – Where the output is drawn.

  • link – The other device, with async read(n) and write(data).

  • keys – A key source with read() returning bytes or None.

  • poll_ms (int) – How often keys are read and the display is redrawn.

  • stop (asyncio.Event) – Set it to end the session. Optional.

Returns:

int – Bytes received from the link.