vtterm.parser

Read VT100 and ANSI escape codes from a byte stream onto a Screen.

Parser.feed takes bytes as they arrive, in pieces of any size: a sequence split across two calls finishes on the second. Printable ASCII goes to the screen in runs. UTF-8 is decoded: box-drawing characters become the screen’s line-drawing cells, and another character the fonts don’t have is drawn as its nearest ASCII or as ?. OSC, DCS and the other string sequences are read and ignored.

What the parser understands:

  • Controls: BS, HT, LF, VT, FF, CR, SO, SI, CAN, SUB, ESC.

  • ESC: 7 8 save and restore, D index, M reverse index, E next line, c reset, # 8 alignment fill, and ( 0 ( B ) 0 ) B to make G0 or G1 the DEC line-drawing set or ASCII.

  • CSI: cursor moves (A to H, f, d, e, a, `), erases (J, K, X), inserts and deletes (@, P, L, M), scrolls (S, T), the scroll region (r), save and restore (s, u), SGR colors and styles (m), modes (h, l) and reports (n, c).

  • SGR: bold, underline, reverse, the 8 and bright 8 colors, 256 colors, and 24-bit color fitted to the nearest of the 256.

  • Modes: insert (4), newline (20), and DEC private cursor keys (1), origin (6), autowrap (7), cursor visible (25), the alternate screen (47, 1047, 1049) and mouse reports (9, 1000, 1002, 1003, with 1006 for the SGR form).

class vtterm.parser.Parser(screen, answer=None)[source]

Bases: object

Turns bytes from a program or a remote board into changes on a Screen.

Parameters:
  • screen (Screen) – The grid to draw on.

  • answer (callable) – Called with the bytes a terminal sends back, such as the cursor position report for ESC [ 6 n. None drops them.

onlcr

Start each new line at column 0, as a tty does for a program that ends lines with a bare \n. Off by default, as on a VT100; Console turns it on.

Type:

bool

feed(data)[source]

Act on data, any number of bytes, continuing an unfinished sequence.

Parameters:

data (bytes) – Bytes from the program or the remote end.