_ | | _ __ _ _ | |_ ___ | '_ \ | | | || __|/ _ \ | |_) || |_| || |_| __/ | .__/ \__, | \__|\___| | | __/ | |_| |___/ 0.4.2 -- chicks dig dudes with terminals (c) @samfoo
pyte? It's an in memory VTXXX-compatible terminal emulator.
XXX stands for a series video terminals, developed by
1970 and 1995. The first, and probably the most famous one, was VT100
terminal, which is now a de-facto standard for all virtual terminal
pyte follows the suit.
So, why would one need a terminal emulator library?
- To screen scrape terminal apps, for example
- To write cross platform terminal emulators; either with a graphical (xterm, rxvt) or a web interface, like AjaxTerm.
- To have fun, hacking on the ancient, poorly documented technologies.
pyte started as a fork of vt102,
which is an incomplete pure Python implementation of VT100 terminal.
There are two important classes in
Screen is the terminal screen emulator. It maintains an in-memory
buffer of text and text-attributes to display on screen. The
is the stream processor. It manages the state of the input and dispatches
events to anything that's listening about things that are going on.
Events are things like
DRAW "a", or
CURSOR_POSITION 10 10.
See the API documentation for more details.
In general, if you just want to know what's being displayed on screen you can do something like the following:
>>> import pyte >>> screen = pyte.Screen(80, 24) >>> stream = pyte.Stream() >>> stream.attach(screen) >>> stream.feed("Hello World!") >>> screen.display ['Hello World! ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']