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:78save and restore,Dindex,Mreverse index,Enext line,creset,# 8alignment fill, and( 0( B) 0) Bto make G0 or G1 the DEC line-drawing set or ASCII.CSI: cursor moves (
AtoH,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:
objectTurns 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.Nonedrops them.