_
| |
_ __ _ _ | |_ ___
| '_ \ | | | || __|/ _ \
| |_) || |_| || |_| __/
| .__/ \__, | \__|\___|
| | __/ |
|_| |___/ 0.5.1
What is pyte
?¶
It’s an in memory VTXXX-compatible terminal emulator.
XXX stands for a series of video terminals, developed by
DEC between
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
emulators. pyte
follows the suit.
So, why would one need a terminal emulator library?
- To screen scrape terminal apps, for example
htop
oraptitude
. - 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.
Note: pyte
started as a fork of vt102,
which is an incomplete pure Python implementation of VT100 terminal.
Installation¶
If you have pip you can do the usual
pip install pyte
. Otherwise, download the source from
GitHub and run
python setup.py install
.
Similar projects¶
pyte
is not alone in the weird world of terminal emulator libraries,
here’s a few other options worth checking out:
Termemulator,
pyqonsole,
webtty,
AjaxTerm and of course
vt102.
pyte
users¶
Believe it or not, there’re projects which actually need a terminal emulator
library. Not many of them use pyte
, though. Here’s a shortlist the ones
that do:
- Ajenti – a webadmin panel for Linux
and BSD uses
pyte
for its terminal plugin. - Pymux – a terminal multiplexor.
Note
Using pyte
? Add yourself to this list and submit a pull request.
Show me the code!¶
Head over to our brief Tutorial or, if you’re feeling brave, dive right
into the API reference; pyte
also has a couple of examples in the
examples directory.
Tutorial¶
There are two important classes in pyte
: Screen
and Stream
. The Screen is the terminal screen
emulator. It maintains an in-memory buffer of text and text-attributes
to display. The Stream is the stream processor. It processes the input
and dispatches events. Events are things like LINEFEED
, DRAW "a"
,
or CURSOR_POSITION 10 10
. See the API reference for more
details.
In general, if you just want to know what’s being displayed on screen you can do something like the following:
>>> fromm __future__ import unicode_literals
>>> import pyte
>>> screen = pyte.Screen(80, 24)
>>> stream = pyte.Stream()
>>> stream.attach(screen)
>>> stream.feed("Hello World!")
>>> screen.display
['Hello World! ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ']
Note: Screen
has no idea what is the source of text, fed into Stream
,
so, obviously, it can’t read or change environment variables, which implies
that:
- it doesn’t adjust LINES and COLUMNS on
"resize"
event; - it doesn’t use locale settings (LC_* and LANG);
- it doesn’t use TERM value and expects it to be “linux” and only “linux”.
And that’s it for Hello World! Head over to the examples for more.
API reference¶
pyte¶
pyte implements a mix of VT100, VT220 and VT520 specification, and aims to support most of the TERM=linux functionality.
Two classes: Stream
, which parses the
command stream and dispatches events for commands, and
Screen
which, when used with a stream
maintains a buffer of strings representing the screen of a
terminal.
Warning
From xterm/main.c
“If you think you know what all
of this code is doing, you are probably very mistaken.
There be serious and nasty dragons here” – nothing
has changed.
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
pyte.streams¶
This module provides three stream implementations with different features; for starters, here’s a quick example of how streams are typically used:
>>> import pyte
>>>
>>> class Dummy(object):
... def __init__(self):
... self.y = 0
...
... def cursor_up(self, count=None):
... self.y += count or 1
...
>>> dummy = Dummy()
>>> stream = pyte.Stream()
>>> stream.attach(dummy)
>>> stream.feed(u"[5A") # Move the cursor up 5 rows.
>>> dummy.y
5
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
-
class
pyte.streams.
ListenerSpec
(screen, only, before, after)¶ An entry in the
Screen
listeners queue.-
after
¶ Alias for field number 3
-
before
¶ Alias for field number 2
-
only
¶ Alias for field number 1
-
screen
¶ Alias for field number 0
-
-
pyte.streams.
noop
(event)[source]¶ A noop before-after hook for
ListenerSpec
.
-
class
pyte.streams.
Stream
[source]¶ A stream is a state machine that parses a stream of characters and dispatches events based on what it sees.
Note
Stream only accepts text as input, but if, for some reason, you need to feed it with bytes, consider using
ByteStream
instead.See also
-
basic
= {'\x0b': 'linefeed', '\r': 'carriage_return', '\x0c': 'linefeed', '\x07': 'bell', '\x08': 'backspace', '\x0e': 'shift_out', '\t': 'tab', '\n': 'linefeed', '\x0f': 'shift_in'}¶ Control sequences, which don’t require any arguments.
-
escape
= {'D': 'index', 'H': 'set_tab_stop', 'E': 'linefeed', 'M': 'reverse_index', '7': 'save_cursor', 'c': 'reset', '8': 'restore_cursor'}¶ non-CSI escape sequences.
-
sharp
= {'8': 'alignment_display'}¶ “sharp” escape sequences –
ESC # <N>
.
-
percent
= {'8': 'charset_utf8', '@': 'charset_default', 'G': 'charset_utf8'}¶ “percent” escape sequences (Linux sequence to select character set) –
ESC % <C>
.
-
csi
= {'n': 'report_device_status', 'H': 'cursor_position', 'J': 'erase_in_display', 'd': 'cursor_to_line', 'B': 'cursor_down', 'l': 'reset_mode', 'X': 'erase_characters', 'f': 'cursor_position', 'P': 'delete_characters', '@': 'insert_characters', 'M': 'delete_lines', 'r': 'set_margins', 'C': 'cursor_forward', 'm': 'select_graphic_rendition', 'c': 'report_device_attributes', 'e': 'cursor_down', 'D': 'cursor_back', 'g': 'clear_tab_stop', 'E': 'cursor_down1', 'G': 'cursor_to_column', 'L': 'insert_lines', "'": 'cursor_to_column', 'F': 'cursor_up1', 'h': 'set_mode', 'K': 'erase_in_line', 'a': 'cursor_forward', 'A': 'cursor_up'}¶ CSI escape sequences –
CSI P1;P2;...;Pn <fn>
.
-
consume
(char)[source]¶ Consumes a single string character and advance the state as necessary.
Parameters: char (str) – a character to consume. Deprecated since version 0.5.0: Use
feed()
instead.
-
feed
(chars)[source]¶ Consumes a string and advance the state as necessary.
Parameters: chars (str) – a string to feed from.
-
attach
(screen, only=())[source]¶ Adds a given screen to the listener queue.
Parameters: - screen (pyte.screens.Screen) – a screen to attach to.
- only (list) – a list of events you want to dispatch to a given screen (empty by default, which means – dispatch all events).
-
detach
(screen)[source]¶ Removes a given screen from the listener queue and fails silently if it’s not attached.
Parameters: screen (pyte.screens.Screen) – a screen to detach.
-
dispatch
(event, *args, **kwargs)[source]¶ Dispatches an event.
Event handlers are looked up implicitly in the screen’s
__dict__
, so, if a screen only wants to handleDRAW
events it should define adraw()
method or passonly=["draw"]
argument toattach()
.Warning
If any of the attached listeners throws an exception, the subsequent callbacks are be aborted.
Parameters: event (str) – event to dispatch.
-
-
class
pyte.streams.
ByteStream
(encodings=None)[source]¶ A stream, which takes bytes (instead of strings) as input and tries to decode them using a given list of possible encodings. It uses
codecs.IncrementalDecoder
internally, so broken bytes are not an issue.By default, the following decoding strategy is used:
- First, try strict
"utf-8"
, proceed if received andUnicodeDecodeError
... - Try strict
"cp437"
, failed? move on ... - Use
"utf-8"
with invalid bytes replaced – this one will always succeed.
>>> stream = ByteStream() >>> stream.feed(b"foo".decode("utf-8")) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pyte/streams.py", line 367, in feed "{0} requires input in bytes".format(self.__class__.__name__)) TypeError: ByteStream requires input in bytes >>> stream.feed(b"foo")
Parameters: encodings (list) – a list of (encoding, errors)
pairs, where the first element is encoding name, ex:"utf-8"
and second defines how decoding errors should be handled; seestr.decode()
for possible values.- First, try strict
-
class
pyte.streams.
DebugStream
(to=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='ANSI_X3.4-1968'>, only=(), *args, **kwargs)[source]¶ Stream, which dumps a subset of the dispatched events to a given file-like object (
sys.stdout
by default).>>> stream = DebugStream() >>> stream.feed("\x1b[1;24r\x1b[4l\x1b[24;1H\x1b[0;10m") SET_MARGINS 1; 24 RESET_MODE 4 CURSOR_POSITION 24; 1 SELECT_GRAPHIC_RENDITION 0; 10
Parameters:
pyte.screens¶
This module provides classes for terminal screens, currently it contains three screens with different features:
Screen
– base screen implementation, which handles all the core escape sequences, recognized byStream
.- If you need a screen to keep track of the changed lines
(which you probably do need) – use
DiffScreen
. - If you also want a screen to collect history and allow
pagination –
pyte.screen.HistoryScreen
is here for ya ;)
Note
It would be nice to split those features into mixin classes, rather than subclasses, but it’s not obvious how to do – feel free to submit a pull request.
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
-
class
pyte.screens.
Cursor
(x, y, attrs=Char(data=' ', fg='default', bg='default', bold=False, italics=False, underscore=False, strikethrough=False, reverse=False))[source]¶ Screen cursor.
Parameters: - x (int) – 0-based horizontal cursor position.
- y (int) – 0-based vertical cursor position.
- attrs (pyte.screens.Char) – cursor attributes (see
select_graphic_rendition()
for details).
-
class
pyte.screens.
Screen
(columns, lines)[source]¶ A screen is an in-memory matrix of characters that represents the screen display of the terminal. It can be instantiated on it’s own and given explicit commands, or it can be attached to a stream and will respond to events.
-
buffer
¶ A
lines x columns
Char
matrix.
-
margins
¶ Top and bottom screen margins, defining the scrolling region; the actual values are top and bottom line.
-
charset
¶ Current charset number; can be either
0
or1
for G0 and G1 respectively, note that G0 is activated by default.
Note
According to
ECMA-48
standard, lines and columns are 1-indexed, so, for instanceESC [ 10;10 f
really means – move cursor to position (9, 9) in the display matrix.Changed in version 0.4.7.
Warning
LNM
is reset by default, to match VT220 specification.Changed in version 0.4.8.
Warning
If DECAWM mode is set than a cursor will be wrapped to the beginning of the next line, which is the behaviour described in
man console_codes
.See also
Standard ECMA-48, Section 6.1.1 for a description of the presentational component, implemented by
Screen
.-
default_char
= Char(data=' ', fg='default', bg='default', bold=False, italics=False, underscore=False, strikethrough=False, reverse=False)¶ A plain empty character with default foreground and background colors.
-
default_line
= repeat(Char(data=' ', fg='default', bg='default', bold=False, italics=False, underscore=False, strikethrough=False, reverse=False))¶ An infinite sequence of default characters, used for populating new lines and columns.
-
display
¶ Returns a
list()
of screen lines as unicode strings.
-
reset
()[source]¶ Resets the terminal to its initial state.
- Scroll margins are reset to screen boundaries.
- Cursor is moved to home location –
(0, 0)
and its attributes are set to defaults (seedefault_char
). - Screen is cleared – each character is reset to
default_char
. - Tabstops are reset to “every eight columns”.
Note
Neither VT220 nor VT102 manuals mentioned that terminal modes and tabstops should be reset as well, thanks to xterm – we now know that.
-
resize
(lines=None, columns=None)[source]¶ Resize the screen to the given dimensions.
If the requested screen size has more lines than the existing screen, lines will be added at the bottom. If the requested size has less lines than the existing screen lines will be clipped at the top of the screen. Similarly, if the existing screen has less columns than the requested screen, columns will be added at the right, and if it has more – columns will be clipped at the right.
Note
According to xterm, we should also reset origin mode and screen margins, see
xterm/screen.c:1761
.Parameters:
-
set_margins
(top=None, bottom=None)[source]¶ Selects top and bottom margins for the scrolling region.
Margins determine which screen lines move during scrolling (see
index()
andreverse_index()
). Characters added outside the scrolling region do not cause the screen to scroll.Parameters:
-
set_charset
(code, mode)[source]¶ Set active
G0
orG1
charset.Parameters: Warning
User-defined charsets are currently not supported.
-
set_mode
(*modes, **kwargs)[source]¶ Sets (enables) a given list of modes.
Parameters: modes (list) – modes to set, where each mode is a constant from pyte.modes
.
-
reset_mode
(*modes, **kwargs)[source]¶ Resets (disables) a given list of modes.
Parameters: modes (list) – modes to reset – hopefully, each mode is a constant from pyte.modes
.
-
draw
(char)[source]¶ Display a character at the current cursor position and advance the cursor if
DECAWM
is set.Parameters: char (str) – a character to display. Changed in version 0.5.0: Character width is taken into account. Specifically, zero-width and unprintable characters do not affect screen state. Full-width characters are rendered into two consecutive character containers.
-
index
()[source]¶ Move the cursor down one line in the same column. If the cursor is at the last line, create a new line at the bottom.
-
reverse_index
()[source]¶ Move the cursor up one line in the same column. If the cursor is at the first line, create a new line at the top.
-
backspace
()[source]¶ Move cursor to the left one or keep it in it’s position if it’s at the beginning of the line already.
-
restore_cursor
()[source]¶ Set the current cursor position to whatever cursor is on top of the stack.
-
insert_lines
(count=None)[source]¶ Inserts the indicated # of lines at line with cursor. Lines displayed at and below the cursor move down. Lines moved past the bottom margin are lost.
Parameters: count – number of lines to delete.
-
delete_lines
(count=None)[source]¶ Deletes the indicated # of lines, starting at line with cursor. As lines are deleted, lines displayed below cursor move up. Lines added to bottom of screen have spaces with same character attributes as last line moved up.
Parameters: count (int) – number of lines to delete.
-
insert_characters
(count=None)[source]¶ Inserts the indicated # of blank characters at the cursor position. The cursor does not move and remains at the beginning of the inserted blank characters. Data on the line is shifted forward.
Parameters: count (int) – number of characters to insert.
-
delete_characters
(count=None)[source]¶ Deletes the indicated # of characters, starting with the character at cursor position. When a character is deleted, all characters to the right of cursor move left. Character attributes move with the characters.
Parameters: count (int) – number of characters to delete.
-
erase_characters
(count=None)[source]¶ Erases the indicated # of characters, starting with the character at cursor position. Character attributes are set cursor attributes. The cursor remains in the same position.
Parameters: count (int) – number of characters to erase. Warning
Even though ALL of the VTXXX manuals state that character attributes should be reset to defaults,
libvte
,xterm
andROTE
completely ignore this. Same applies too allerase_*()
anddelete_*()
methods.
-
erase_in_line
(how=0, private=False)[source]¶ Erases a line in a specific way.
Parameters: - how (int) –
defines the way the line should be erased in:
0
– Erases from cursor to end of line, including cursor position.1
– Erases from beginning of line to cursor, including cursor position.2
– Erases complete line.
- private (bool) – when
True
character attributes are left unchanged not implemented.
- how (int) –
-
erase_in_display
(how=0, private=False)[source]¶ Erases display in a specific way.
Parameters: - how (int) –
defines the way the line should be erased in:
0
– Erases from cursor to end of screen, including cursor position.1
– Erases from beginning of screen to cursor, including cursor position.2
– Erases complete display. All lines are erased and changed to single-width. Cursor does not move.
- private (bool) – when
True
character attributes are left unchanged not implemented.
- how (int) –
-
clear_tab_stop
(how=0)[source]¶ Clears a horizontal tab stop.
Parameters: how (int) – defines a way the tab stop should be cleared:
0
or nothing – Clears a horizontal tab stop at cursor position.3
– Clears all horizontal tab stops.
-
ensure_bounds
(use_margins=None)[source]¶ Ensure that current cursor position is within screen bounds.
Parameters: use_margins (bool) – when True
or whenDECOM
is set, cursor is bounded by top and and bottom margins, instead of[0; lines - 1]
.
-
cursor_up
(count=None)[source]¶ Moves cursor up the indicated # of lines in same column. Cursor stops at top margin.
Parameters: count (int) – number of lines to skip.
-
cursor_up1
(count=None)[source]¶ Moves cursor up the indicated # of lines to column 1. Cursor stops at bottom margin.
Parameters: count (int) – number of lines to skip.
-
cursor_down
(count=None)[source]¶ Moves cursor down the indicated # of lines in same column. Cursor stops at bottom margin.
Parameters: count (int) – number of lines to skip.
-
cursor_down1
(count=None)[source]¶ Moves cursor down the indicated # of lines to column 1. Cursor stops at bottom margin.
Parameters: count (int) – number of lines to skip.
-
cursor_back
(count=None)[source]¶ Moves cursor left the indicated # of columns. Cursor stops at left margin.
Parameters: count (int) – number of columns to skip.
-
cursor_forward
(count=None)[source]¶ Moves cursor right the indicated # of columns. Cursor stops at right margin.
Parameters: count (int) – number of columns to skip.
-
cursor_position
(line=None, column=None)[source]¶ Set the cursor to a specific line and column.
Cursor is allowed to move out of the scrolling region only when
DECOM
is reset, otherwise – the position doesn’t change.Parameters:
-
cursor_to_column
(column=None)[source]¶ Moves cursor to a specific column in the current line.
Parameters: column (int) – column number to move the cursor to.
-
cursor_to_line
(line=None)[source]¶ Moves cursor to a specific line in the current column.
Parameters: line (int) – line number to move the cursor to.
-
bell
(*args)[source]¶ Bell stub – the actual implementation should probably be provided by the end-user.
-
select_graphic_rendition
(*attrs)[source]¶ Set display attributes.
Parameters: attrs (list) – a list of display attributes to set.
-
-
class
pyte.screens.
DiffScreen
(*args)[source]¶ A screen subclass, which maintains a set of dirty lines in its
dirty
attribute. The end user is responsible for emptying a set, when a diff is applied.-
dirty
¶ A set of line numbers, which should be re-drawn.
>>> screen = DiffScreen(80, 24) >>> screen.dirty.clear() >>> screen.draw(u"!") >>> screen.dirty set([0])
-
-
class
pyte.screens.
HistoryScreen
(columns, lines, history=100, ratio=0.5)[source]¶ A screen subclass, which keeps track of screen history and allows pagination. This is not linux-specific, but still useful; see page 462 of VT520 User’s Manual.
Parameters: - history (int) – total number of history lines to keep; is split between top and bottom queues.
- ratio (int) – defines how much lines to scroll on
next_page()
andprev_page()
calls.
-
history
¶ A pair of history queues for top and bottom margins accordingly; here’s the overall screen structure:
[ 1: .......] [ 2: .......] <- top history [ 3: .......] ------------ [ 4: .......] s [ 5: .......] c [ 6: .......] r [ 7: .......] e [ 8: .......] e [ 9: .......] n ------------ [10: .......] [11: .......] <- bottom history [12: .......]
Note
Don’t forget to update
Stream
class with appropriate escape sequences – you can use any, since pagination protocol is not standardized, for example:Stream.escape["N"] = "next_page" Stream.escape["P"] = "prev_page"
-
reset
()[source]¶ Overloaded to reset screen history state: history position is reset to bottom of both queues; queues themselves are emptied.
pyte.modes¶
This module defines terminal mode switches, used by
Screen
. There’re two types of terminal modes:
- non-private which should be set with
ESC [ N h
, whereN
is an integer, representing mode being set; and - private which should be set with
ESC [ ? N h
.
The latter are shifted 5 times to the right, to be easily
distinguishable from the former ones; for example Origin Mode
– DECOM
is 192
not 6
.
>>> DECOM
192
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
-
pyte.modes.
LNM
= 20¶ Line Feed/New Line Mode: When enabled, causes a received
LF
,pyte.control.FF
, orVT
to move the cursor to the first column of the next line.
-
pyte.modes.
IRM
= 4¶ Insert/Replace Mode: When enabled, new display characters move old display characters to the right. Characters moved past the right margin are lost. Otherwise, new display characters replace old display characters at the cursor position.
-
pyte.modes.
DECTCEM
= 800¶ Text Cursor Enable Mode: determines if the text cursor is visible.
-
pyte.modes.
DECSCNM
= 160¶ Screen Mode: toggles screen-wide reverse-video mode.
-
pyte.modes.
DECOM
= 192¶ Origin Mode: allows cursor addressing relative to a user-defined origin. This mode resets when the terminal is powered up or reset. It does not affect the erase in display (ED) function.
-
pyte.modes.
DECAWM
= 224¶ Auto Wrap Mode: selects where received graphic characters appear when the cursor is at the right margin.
-
pyte.modes.
DECCOLM
= 96¶ Column Mode: selects the number of columns per line (80 or 132) on the screen.
pyte.control¶
This module defines simple control sequences, recognized by
Stream
, the set of codes here is for
TERM=linux
which is a superset of VT102.
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
-
pyte.control.
SP
= ' '¶ Space: Not suprisingly –
" "
.
-
pyte.control.
NUL
= '\x00'¶ Null: Does nothing.
-
pyte.control.
BEL
= '\x07'¶ Bell: Beeps.
-
pyte.control.
BS
= '\x08'¶ Backspace: Backspace one column, but not past the begining of the line.
-
pyte.control.
HT
= '\t'¶ Horizontal tab: Move cursor to the next tab stop, or to the end of the line if there is no earlier tab stop.
-
pyte.control.
LF
= '\n'¶ Linefeed: Give a line feed, and, if
pyte.modes.LNM
(new line mode) is set also a carriage return.
-
pyte.control.
CR
= '\r'¶ Carriage return: Move cursor to left margin on current line.
-
pyte.control.
SO
= '\x0e'¶ Shift out: Activate G1 character set.
-
pyte.control.
SI
= '\x0f'¶ Shift in: Activate G0 character set.
-
pyte.control.
CAN
= '\x18'¶ Cancel: Interrupt escape sequence. If received during an escape or control sequence, cancels the sequence and displays substitution character.
-
pyte.control.
ESC
= '\x1b'¶ Escape: Starts an escape sequence.
-
pyte.control.
DEL
= '\x7f'¶ Delete: Is ignored.
-
pyte.control.
CSI
= '\x9b'¶ Control sequence introducer: An equivalent for
ESC [
.
pyte.escape¶
This module defines both CSI and non-CSI escape sequences, recognized
by Stream
and subclasses.
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
-
pyte.escape.
RIS
= 'c'¶ Reset.
-
pyte.escape.
IND
= 'D'¶ Index: Move cursor down one line in same column. If the cursor is at the bottom margin, the screen performs a scroll-up.
-
pyte.escape.
NEL
= 'E'¶ Next line: Same as
pyte.control.LF
.
-
pyte.escape.
HTS
= 'H'¶ Tabulation set: Set a horizontal tab stop at cursor position.
-
pyte.escape.
RI
= 'M'¶ Reverse index: Move cursor up one line in same column. If the cursor is at the top margin, the screen performs a scroll-down.
-
pyte.escape.
DECSC
= '7'¶ Save cursor: Save cursor position, character attribute (graphic rendition), character set, and origin mode selection (see
DECRC
).
-
pyte.escape.
DECRC
= '8'¶ Restore cursor: Restore previously saved cursor position, character attribute (graphic rendition), character set, and origin mode selection. If none were saved, move cursor to home position.
-
pyte.escape.
DEFAULT
= '@'¶ Select default (ISO 646 / ISO 8859-1).
-
pyte.escape.
UTF8
= 'G'¶ Select UTF-8.
-
pyte.escape.
UTF8_OBSOLETE
= '8'¶ Select UTF-8 (obsolete).
-
pyte.escape.
DECALN
= '8'¶ Alignment display: Fill screen with uppercase E’s for testing screen focus and alignment.
-
pyte.escape.
ICH
= '@'¶ Insert character: Insert the indicated # of blank characters.
-
pyte.escape.
CUU
= 'A'¶ Cursor up: Move cursor up the indicated # of lines in same column. Cursor stops at top margin.
-
pyte.escape.
CUD
= 'B'¶ Cursor down: Move cursor down the indicated # of lines in same column. Cursor stops at bottom margin.
-
pyte.escape.
CUF
= 'C'¶ Cursor forward: Move cursor right the indicated # of columns. Cursor stops at right margin.
-
pyte.escape.
CUB
= 'D'¶ Cursor back: Move cursor left the indicated # of columns. Cursor stops at left margin.
-
pyte.escape.
CNL
= 'E'¶ Cursor next line: Move cursor down the indicated # of lines to column 1.
-
pyte.escape.
CPL
= 'F'¶ Cursor previous line: Move cursor up the indicated # of lines to column 1.
-
pyte.escape.
CHA
= 'G'¶ Cursor horizontal align: Move cursor to the indicated column in current line.
-
pyte.escape.
CUP
= 'H'¶ Cursor position: Move cursor to the indicated line, column (origin at
1, 1
).
-
pyte.escape.
ED
= 'J'¶ Erase data (default: from cursor to end of line).
-
pyte.escape.
EL
= 'K'¶ Erase in line (default: from cursor to end of line).
-
pyte.escape.
IL
= 'L'¶ Insert line: Insert the indicated # of blank lines, starting from the current line. Lines displayed below cursor move down. Lines moved past the bottom margin are lost.
-
pyte.escape.
DL
= 'M'¶ Delete line: Delete the indicated # of lines, starting from the current line. As lines are deleted, lines displayed below cursor move up. Lines added to bottom of screen have spaces with same character attributes as last line move up.
-
pyte.escape.
DCH
= 'P'¶ Delete character: Delete the indicated # of characters on the current line. When character is deleted, all characters to the right of cursor move left.
-
pyte.escape.
ECH
= 'X'¶ Erase character: Erase the indicated # of characters on the current line.
-
pyte.escape.
DA
= 'c'¶ Device Attributes.
-
pyte.escape.
VPA
= 'd'¶ Vertical position adjust: Move cursor to the indicated line, current column.
-
pyte.escape.
TBC
= 'g'¶ Tabulation clear: Clears a horizontal tab stop at cursor position.
-
pyte.escape.
SM
= 'h'¶ Set mode.
-
pyte.escape.
RM
= 'l'¶ Reset mode.
-
pyte.escape.
SGR
= 'm'¶ Select graphics rendition: The terminal can display the following character attributes that change the character display without changing the character (see
pyte.graphics
).
-
pyte.escape.
DSR
= 'n'¶ Device status report.
-
pyte.escape.
DECSTBM
= 'r'¶ Select top and bottom margins: Selects margins, defining the scrolling region; parameters are top and bottom line. If called without any arguments, whole screen is used.
pyte.graphics¶
This module defines graphic-related constants, mostly taken from console_codes(4) and http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html.
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
-
pyte.graphics.
TEXT
= {27: '-reverse', 1: '+bold', 3: '+italics', 4: '+underscore', 22: '-bold', 7: '+reverse', 24: '-underscore', 9: '+strikethrough', 23: '-italics', 29: '-strikethrough'}¶ A mapping of ANSI text style codes to style names, “+” means the: attribute is set, “-” – reset; example:
>>> text[1] '+bold' >>> text[9] '+strikethrough'
-
pyte.graphics.
FG
= {32: 'green', 33: 'brown', 34: 'blue', 35: 'magenta', 36: 'cyan', 37: 'white', 39: 'default', 30: 'black', 31: 'red'}¶ A mapping of ANSI foreground color codes to color names, example:
>>> FG[30] 'black' >>> FG[38] 'default'
-
pyte.graphics.
BG
= {49: 'default', 40: 'black', 41: 'red', 42: 'green', 43: 'brown', 44: 'blue', 45: 'magenta', 46: 'cyan', 47: 'white'}¶ A mapping of ANSI background color codes to color names, example:
>>> BG[40] 'black' >>> BG[48] 'default'
pyte.charsets¶
This module defines G0
and G1
charset mappings the same way
they are defined for linux terminal, see
linux/drivers/tty/consolemap.c
@ http://git.kernel.org
Note
VT100_MAP
and IBMPC_MAP
were taken unchanged
from linux kernel source and therefore are licensed
under GPL.
copyright: |
|
---|---|
license: | LGPL, see LICENSE for more details. |
-
pyte.charsets.
LAT1_MAP
= ['\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', '\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '\x7f', '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f', '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', '\xa0', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '\xad', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ']¶ Latin1.
-
pyte.charsets.
VT100_MAP
= '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*→←↑↓/█123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^\xa0◆▒␉␌␍␊°±░␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π≠£·\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0¡¢£¤¥¦§¨©ª«¬\xad®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'¶ VT100 graphic character set.
-
pyte.charsets.
IBMPC_MAP
= '\x00☺☻♥♦♣♠•◘○◙♂♀♪♫☼▶◀↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xa0'¶ IBM Codepage 437.
-
pyte.charsets.
VAX42_MAP
= '\x00☺☻♥♦♣♠•◘○◙♂♀♪♫☼▶◀↕‼¶§▬↨↑↓→←∟↔▲▼ л"#$%&\'()*+,-./0123456789:;<=>е@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`сbcdefgеijklmnкpqтsлеvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xa0'¶ VAX42 character set.
pyte Changelog¶
Here you can see the full list of changes between each pyte release.
Version 0.5.0¶
Released on January 10th 2015
- Deprecated
Stream.consume
in favour ofStream.feed
. The latter allows for a more efficient implementation because it operates on the whole input string. - Improved
Stream
performance by converting FSM to a coroutine as suggested by Jonathan Slenders in issue #41 on GitHub. - Added support for DA (device attributes) and DSR (device status report). The implementation is based on the code by Jonathan Slenders. See issue #41 on GitHub.
Screen.draw
now properly handles full/ambiguous-width characters. Thanks to the excellent wcwidth library by Jeff Quast.- Removed re-exports of abbreviated modules (e.g.
mo
as a synonym formodes
) frompyte
. - Removed
Screen.size
which misleadingly returned constructor arguments in reverse order. Please useScreen.columns
andScreen.lines
instead. - Fixed a bug in
ByteStream
which suppressed the exception if all of the decoders failed to process the input.
Version 0.4.10¶
Bugfix release, released on August 4th 2015
- Fixed a bug in
DiffScreen.draw
which marked the wrong line as changed when DECAWM was enabled. Stream
now recognizes ESC % sequences for selecting control character set. However, these operations are no-op in the current version in a sense thatByteStream
does not handle them to change encoding.
Version 0.4.9¶
Bugfix release, released on December 3rd 2014
- Fixed a bug in
Char
initialization, see issue #24 on GitHub for details. - Updated error message in
Stream
, referencingstr
is relevant for Python 3, but not Python 2.
Version 0.4.8¶
Released on January 13th 2014
Screen
does NOT inherit from builtinlist
, useScreen.buffer
to access individual characters directly. This is a backward INCOMPATIBLE change.Char._asdict
was broken on Python 3.3 because of the changes innamedtuple
implementation.LAT1_MAP
was an iterator because of the change in map semantics in Python 3.- Changed
Screen
to issues a CR in addition to LF when DECAWM mode is set and the cursor is at the right border of the screen. See http://www.vt100.net/docs/vt510-rm/DECAWM and issue #20 on GitHub for details.
Version 0.4.7¶
Bugfix release, released on March 28th 2013
- Updated
pyte
and tests suite to work under Python 3.3. - Changed
Screen
so that LNM mode is reset by default, see http://www.vt100.net/docs/vt510-rm/LNM and issue #11 on GitHub for details.
Version 0.4.6¶
Bugfix release, released on February 29th 2012
Version 0.4.5¶
Technical release, released on September 1st 2011
- Added MANIFEST.in and CenOS spec file
Version 0.4.4¶
Bugfix release, released on July 17th 2011
- Removed
pdb
calls, left fromHistoryScreen
debugging – silly, I know :)
Version 0.4.3¶
Bugfix release, released on July 12th 2011
- Fixed encoding issues in
DebugStream
– Unicode was not converted to bytes properly. - Fixed G0-1 charset handling and added VAX42 charset for the ancient stuff to work correctly.
Version 0.4.2¶
Bugfix release, released on June 27th 2011
- Added a tiny debugging helper:
python -m pyte your escape codes
- Added
Screen.__{before,after}__()
hooks toScreen
– now subclasses can extend more than one command easily. - Fixed
HistoryScreen
– now not as buggy as it used to be: and allows for custom ratio aspect when browsing history, seeHistoryScreen
documentation for details. - Fixed DECTCEM private mode handling – when the mode is reset
Screen.cursor.hidden
isTrue
otherwise it’sFalse
.
Version 0.4.1¶
Bugfix release, released on June 21st 2011
- Minor examples and documentation update before the first public release.
Version 0.4.0¶
Released on June 21st 2011
- Improved cursor movement –
Screen
passes all but one tests in vttest. - Changed the way
Stream
interacts withScreen
– event handlers are now implicitly looked up in screen’s__dict__
, not connected manually. - Changed cursor API – cursor position and attributes are encapsulated
in a separate
Cursor
class. - Added support for DECSCNM – toggle screen-wide reverse-video mode.
- Added a couple of useful
Screen
subclasses:HistoryScreen
which allows screen pagination andDiffScreen
which tracks the changed lines.
Version 0.3.9¶
Released on May 31st 2011
- Added initial support for G0-1 charsets (mappings taken from
tty
kernel driver) and SI, SO escape sequences. - Changed
ByteStream
to support fallback encodings – it now takes a list of(encoding, errors)
pairs and traverses it left to right onfeed()
. - Switched to
unicode_literals
– one step closer to Python3.
Version 0.3.8¶
Released on May 23rd 2011
- Major rewrite of
Screen
internals – highlights: inherits fromlist
; each character is represented bynamedtuple
which also holds SGR data. - Numerous bugfixes, especially in methods, dealing with manipulating character attributes.
Version 0.3.7¶
First release after the adoption – skipped a few version to reflect that. Released on May 16th 2011
- Added support for ANSI color codes, as listed in
man console_codes
. Not implemented yet: setting alternate font, setting and resetting mappings, blinking text. - Added a couple of trivial usage examples in the examples/ dir.