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:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

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
>>> screen = pyte.Screen(80, 24)
>>> stream = pyte.Stream(screen)
>>> stream.feed(b"")  # Move the cursor down 5 rows.
>>> screen.cursor.y
5
copyright:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

license:

LGPL, see LICENSE for more details.

class pyte.streams.Stream(screen=None, strict=True)[source]

A stream is a state machine that parses a stream of bytes and dispatches events based on what it sees.

Parameters:
  • screen (pyte.screens.Screen) – a screen to dispatch events to.
  • strict (bool) – check if a given screen implements all required events.

Note

Stream only accepts bytes() as input. Decoding it into text is the responsibility of the Screen.

See also

man console_codes
For details on console codes listed bellow in basic, escape, csi, sharp and percent.
basic = {b'\x0f': 'shift_in', b'\t': 'tab', b'\r': 'carriage_return', b'\n': 'linefeed', b'\x0b': 'linefeed', b'\x0c': 'linefeed', b'\x07': 'bell', b'\x08': 'backspace', b'\x0e': 'shift_out'}

Control sequences, which don’t require any arguments.

escape = {b'H': 'set_tab_stop', b'D': 'index', b'7': 'save_cursor', b'8': 'restore_cursor', b'E': 'linefeed', b'M': 'reverse_index', b'c': 'reset'}

non-CSI escape sequences.

sharp = {b'8': 'alignment_display'}

“sharp” escape sequences – ESC # <N>.

csi = {b'H': 'cursor_position', b'C': 'cursor_forward', b'm': 'select_graphic_rendition', b'K': 'erase_in_line', b'X': 'erase_characters', b'@': 'insert_characters', b'h': 'set_mode', b'G': 'cursor_to_column', b"'": 'cursor_to_column', b'P': 'delete_characters', b'd': 'cursor_to_line', b'l': 'reset_mode', b'J': 'erase_in_display', b'L': 'insert_lines', b'a': 'cursor_forward', b'B': 'cursor_down', b'f': 'cursor_position', b'g': 'clear_tab_stop', b'A': 'cursor_up', b'r': 'set_margins', b'E': 'cursor_down1', b'n': 'report_device_status', b'F': 'cursor_up1', b'D': 'cursor_back', b'e': 'cursor_down', b'c': 'report_device_attributes', b'M': 'delete_lines'}

CSI escape sequences – CSI P1;P2;...;Pn <fn>.

events = frozenset({'select_graphic_rendition', 'erase_in_line', 'set_mode', 'set_title', 'alignment_display', 'reset', 'reset_mode', 'draw', 'bell', 'select_other_charset', 'cursor_up1', 'backspace', 'cursor_to_line', 'report_device_status', 'debug', 'shift_out', 'shift_in', 'cursor_position', 'delete_characters', 'cursor_to_column', 'clear_tab_stop', 'report_device_attributes', 'restore_cursor', 'set_icon', 'save_cursor', 'set_margins', 'tab', 'index', 'cursor_down', 'define_charset', 'reverse_index', 'cursor_forward', 'insert_lines', 'set_tab_stop', 'cursor_back', 'insert_characters', 'linefeed', 'cursor_down1', 'erase_characters', 'delete_lines', 'carriage_return', 'erase_in_display', 'cursor_up'})

A set of all events dispatched by the stream.

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.
feed(data)[source]

Consumes a string and advances the state as necessary.

Parameters:data (bytes) – a blob of data to feed from.
class pyte.streams.DebugStream(to=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, only=(), *args, **kwargs)[source]

Stream, which dumps a subset of the dispatched events to a given file-like object (sys.stdout by default).

>>> import io
>>> with io.StringIO() as buf:
...     stream = DebugStream(to=buf)
...     stream.feed(b"\x1b[1;24r\x1b[4l\x1b[24;1H\x1b[0;10m")
...     print(buf.getvalue())
...
... 
SET_MARGINS 1; 24
RESET_MODE 4
CURSOR_POSITION 24; 1
SELECT_GRAPHIC_RENDITION 0; 10
Parameters:
  • to (file) – a file-like object to write debug information to.
  • only (list) – a list of events you want to debug (empty by default, which means – debug all events).

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 by Stream.
  • 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:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

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.

cursor

Reference to the Cursor object, holding cursor position and attributes.

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 or 1 for G0 and G1 respectively, note that G0 is activated by default.

use_utf8

Assume the input to draw() is encoded using UTF-8. Defaults to True.

Note

According to ECMA-48 standard, lines and columns are 1-indexed, so, for instance ESC [ 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 (see default_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:
  • lines (int) – number of lines in the new screen.
  • columns (int) – number of columns in the new screen.
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() and reverse_index()). Characters added outside the scrolling region do not cause the screen to scroll.

Parameters:
  • top (int) – the smallest line number that is scrolled.
  • bottom (int) – the biggest line number that is scrolled.
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.
define_charset(code, mode)[source]

Defines G0 or G1 charset.

Parameters:
  • code (str) – character set code, should be a character from b"B0UK", otherwise ignored.
  • mode (str) – if "(" G0 charset is defined, if ")" – we operate on G1.

Warning

User-defined charsets are currently not supported.

shift_in()[source]

Selects G0 character set.

shift_out()[source]

Selects G1 character set.

select_other_charset(code)[source]

Selects other (non G0 or G1) charset.

Parameters:code (str) – character set code, should be a character from b"@G8", otherwise ignored.

Note

We currently follow "linux" and only use this command to switch from ISO-8859-1 to UTF-8 and back.

Standard ECMA-35, Section 15.4 for a description of VTXXX character set machinery.

draw(data)[source]

Displays decoded characters at the current cursor position and advances the cursor if DECAWM is set.

Parameters:data (bytes) – bytes 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.

Changed in version 0.6.0: The input is now supposed to be in bytes(), which may encode multiple characters.

set_title(param)[source]

Sets terminal title.

Note

This is an XTerm extension supported by the Linux terminal.

set_icon_name(param)[source]

Sets icon name.

Note

This is an XTerm extension supported by the Linux terminal.

carriage_return()[source]

Move the cursor to the beginning of the current line.

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.

linefeed()[source]

Performs an index and, if LNM is set, a carriage return.

tab()[source]

Move to the next tab space, or the end of the screen if there aren’t anymore left.

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.

save_cursor()[source]

Push the current cursor position onto the stack.

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 and ROTE completely ignore this. Same applies too all erase_*() and delete_*() 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.
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.
set_tab_stop()[source]

Sets a horizontal tab stop at cursor position.

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 when DECOM 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:
  • line (int) – line number to move the cursor to.
  • column (int) – column number to move the cursor to.
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.

alignment_display()[source]

Fills screen with uppercase E’s for screen focus and alignment.

select_graphic_rendition(*attrs)[source]

Set display attributes.

Parameters:attrs (list) – a list of display attributes to set.
report_device_attributes(mode=0, **kwargs)[source]

Reports terminal identity.

New in version 0.5.0.

report_device_status(mode)[source]

Reports terminal status or cursor position.

Parameters:mode (int) – if 5 – terminal status, 6 – cursor position, otherwise a noop.

New in version 0.5.0.

write_process_input(data)[source]

Writes data to the process running inside the terminal.

By default is a noop.

Parameters:data (bytes) – data to write to the process stdin.

New in version 0.5.0.

debug(*args, **kwargs)[source]

Endpoint for unrecognized escape sequences.

By default is a noop.

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("!")
>>> list(screen.dirty)
[0]
class pyte.screens.HistoryScreen(columns, lines, history=100, ratio=0.5)[source]

A :class:~`pyte.screens.DiffScreen` 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() and prev_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[b"N"] = "next_page"
Stream.escape[b"P"] = "prev_page"
before_event(event)[source]

Ensures a screen is at the bottom of the history buffer.

Parameters:event (str) – event name, for example "linefeed".
after_event(event)[source]

Ensures all lines on a screen have proper width (columns).

Extra characters are truncated, missing characters are filled with whitespace.

Parameters:event (str) – event name, for example "linefeed".
reset()[source]

Overloaded to reset screen history state: history position is reset to bottom of both queues; queues themselves are emptied.

index()[source]

Overloaded to update top history with the removed lines.

reverse_index()[source]

Overloaded to update bottom history with the removed lines.

prev_page()[source]

Moves the screen page up through the history buffer. Page size is defined by history.ratio, so for instance ratio = .5 means that half the screen is restored from history on page switch.

next_page()[source]

Moves the screen page down through the history buffer.

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, where N 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 ModeDECOM is 192 not 6.

>>> DECOM
192
copyright:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

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, or VT 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:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

license:

LGPL, see LICENSE for more details.

pyte.control.SP = b' '

Space: Not suprisingly – " ".

pyte.control.NUL = b'\x00'

Null: Does nothing.

pyte.control.BEL = b'\x07'

Bell: Beeps.

pyte.control.BS = b'\x08'

Backspace: Backspace one column, but not past the begining of the line.

pyte.control.HT = b'\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 = b'\n'

Linefeed: Give a line feed, and, if pyte.modes.LNM (new line mode) is set also a carriage return.

pyte.control.VT = b'\x0b'

Vertical tab: Same as LF.

pyte.control.FF = b'\x0c'

Form feed: Same as LF.

pyte.control.CR = b'\r'

Carriage return: Move cursor to left margin on current line.

pyte.control.SO = b'\x0e'

Shift out: Activate G1 character set.

pyte.control.SI = b'\x0f'

Shift in: Activate G0 character set.

pyte.control.CAN = b'\x18'

Cancel: Interrupt escape sequence. If received during an escape or control sequence, cancels the sequence and displays substitution character.

pyte.control.SUB = b'\x1a'

Substitute: Same as CAN.

pyte.control.ESC = b'\x1b'

Escape: Starts an escape sequence.

pyte.control.DEL = b'\x7f'

Delete: Is ignored.

pyte.control.CSI = b'\x9b'

Control sequence introducer: An equivalent for ESC [.

pyte.control.ST = b'\x9c'

String terminator.

pyte.control.OSC = b'\x9d'

Operating system command.

pyte.escape

This module defines both CSI and non-CSI escape sequences, recognized by Stream and subclasses.

copyright:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

license:

LGPL, see LICENSE for more details.

pyte.escape.RIS = b'c'

Reset.

pyte.escape.IND = b'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 = b'E'

Next line: Same as pyte.control.LF.

pyte.escape.HTS = b'H'

Tabulation set: Set a horizontal tab stop at cursor position.

pyte.escape.RI = b'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 = b'7'

Save cursor: Save cursor position, character attribute (graphic rendition), character set, and origin mode selection (see DECRC).

pyte.escape.DECRC = b'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.DECALN = b'8'

Alignment display: Fill screen with uppercase E’s for testing screen focus and alignment.

pyte.escape.ICH = b'@'

Insert character: Insert the indicated # of blank characters.

pyte.escape.CUU = b'A'

Cursor up: Move cursor up the indicated # of lines in same column. Cursor stops at top margin.

pyte.escape.CUD = b'B'

Cursor down: Move cursor down the indicated # of lines in same column. Cursor stops at bottom margin.

pyte.escape.CUF = b'C'

Cursor forward: Move cursor right the indicated # of columns. Cursor stops at right margin.

pyte.escape.CUB = b'D'

Cursor back: Move cursor left the indicated # of columns. Cursor stops at left margin.

pyte.escape.CNL = b'E'

Cursor next line: Move cursor down the indicated # of lines to column 1.

pyte.escape.CPL = b'F'

Cursor previous line: Move cursor up the indicated # of lines to column 1.

pyte.escape.CHA = b'G'

Cursor horizontal align: Move cursor to the indicated column in current line.

pyte.escape.CUP = b'H'

Cursor position: Move cursor to the indicated line, column (origin at 1, 1).

pyte.escape.ED = b'J'

Erase data (default: from cursor to end of line).

pyte.escape.EL = b'K'

Erase in line (default: from cursor to end of line).

pyte.escape.IL = b'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 = b'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 = b'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 = b'X'

Erase character: Erase the indicated # of characters on the current line.

pyte.escape.HPR = b'a'

Horizontal position relative: Same as CUF.

pyte.escape.DA = b'c'

Device Attributes.

pyte.escape.VPA = b'd'

Vertical position adjust: Move cursor to the indicated line, current column.

pyte.escape.VPR = b'e'

Vertical position relative: Same as CUD.

pyte.escape.HVP = b'f'

Horizontal / Vertical position: Same as CUP.

pyte.escape.TBC = b'g'

Tabulation clear: Clears a horizontal tab stop at cursor position.

pyte.escape.SM = b'h'

Set mode.

pyte.escape.RM = b'l'

Reset mode.

pyte.escape.SGR = b'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 = b'n'

Device status report.

pyte.escape.DECSTBM = b'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.escape.HPA = b"'"

Horizontal position adjust: Same as CHA.

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:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

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_ANSI = {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.

>>> FG_ANSI[30]
'black'
>>> FG_ANSI[38]
'default'
pyte.graphics.FG = {32: 'green', 33: 'brown', 34: 'blue', 35: 'magenta', 36: 'cyan', 37: 'white', 39: 'default', 30: 'black', 31: 'red'}

An alias to FG_ANSI for compatibility.

pyte.graphics.FG_AIXTERM = {96: 'cyan', 97: 'white', 90: 'black', 91: 'red', 92: 'green', 93: 'brown', 94: 'blue', 95: 'magenta'}

A mapping of non-standard aixterm foreground color codes to color names. These are high intensity colors and thus should be complemented by +bold.

pyte.graphics.BG_ANSI = {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.

>>> BG_ANSI[40]
'black'
>>> BG_ANSI[48]
'default'
pyte.graphics.BG = {49: 'default', 40: 'black', 41: 'red', 42: 'green', 43: 'brown', 44: 'blue', 45: 'magenta', 46: 'cyan', 47: 'white'}

An alias to BG_ANSI for compatibility.

pyte.graphics.BG_AIXTERM = {100: 'black', 101: 'red', 102: 'green', 103: 'brown', 104: 'blue', 105: 'magenta', 106: 'cyan', 107: 'white'}

A mapping of non-standard aixterm background color codes to color names. These are high intensity colors and thus should be complemented by +bold.

pyte.graphics.FG_256 = 38

SGR code for foreground in 256 or True color mode.

pyte.graphics.BG_256 = 48

SGR code for background in 256 or True color mode.

pyte.graphics.FG_BG_256 = ['000000', 'cd0000', '00cd00', 'cdcd00', '0000ee', 'cd00cd', '00cdcd', 'e5e5e5', '7f7f7f', 'ff0000', '00ff00', 'ffff00', '5c5cff', 'ff00ff', '00ffff', 'ffffff', '000000', '00005f', '000087', '0000af', '0000d7', '0000ff', '005f00', '005f5f', '005f87', '005faf', '005fd7', '005fff', '008700', '00875f', '008787', '0087af', '0087d7', '0087ff', '00af00', '00af5f', '00af87', '00afaf', '00afd7', '00afff', '00d700', '00d75f', '00d787', '00d7af', '00d7d7', '00d7ff', '00ff00', '00ff5f', '00ff87', '00ffaf', '00ffd7', '00ffff', '5f0000', '5f005f', '5f0087', '5f00af', '5f00d7', '5f00ff', '5f5f00', '5f5f5f', '5f5f87', '5f5faf', '5f5fd7', '5f5fff', '5f8700', '5f875f', '5f8787', '5f87af', '5f87d7', '5f87ff', '5faf00', '5faf5f', '5faf87', '5fafaf', '5fafd7', '5fafff', '5fd700', '5fd75f', '5fd787', '5fd7af', '5fd7d7', '5fd7ff', '5fff00', '5fff5f', '5fff87', '5fffaf', '5fffd7', '5fffff', '870000', '87005f', '870087', '8700af', '8700d7', '8700ff', '875f00', '875f5f', '875f87', '875faf', '875fd7', '875fff', '878700', '87875f', '878787', '8787af', '8787d7', '8787ff', '87af00', '87af5f', '87af87', '87afaf', '87afd7', '87afff', '87d700', '87d75f', '87d787', '87d7af', '87d7d7', '87d7ff', '87ff00', '87ff5f', '87ff87', '87ffaf', '87ffd7', '87ffff', 'af0000', 'af005f', 'af0087', 'af00af', 'af00d7', 'af00ff', 'af5f00', 'af5f5f', 'af5f87', 'af5faf', 'af5fd7', 'af5fff', 'af8700', 'af875f', 'af8787', 'af87af', 'af87d7', 'af87ff', 'afaf00', 'afaf5f', 'afaf87', 'afafaf', 'afafd7', 'afafff', 'afd700', 'afd75f', 'afd787', 'afd7af', 'afd7d7', 'afd7ff', 'afff00', 'afff5f', 'afff87', 'afffaf', 'afffd7', 'afffff', 'd70000', 'd7005f', 'd70087', 'd700af', 'd700d7', 'd700ff', 'd75f00', 'd75f5f', 'd75f87', 'd75faf', 'd75fd7', 'd75fff', 'd78700', 'd7875f', 'd78787', 'd787af', 'd787d7', 'd787ff', 'd7af00', 'd7af5f', 'd7af87', 'd7afaf', 'd7afd7', 'd7afff', 'd7d700', 'd7d75f', 'd7d787', 'd7d7af', 'd7d7d7', 'd7d7ff', 'd7ff00', 'd7ff5f', 'd7ff87', 'd7ffaf', 'd7ffd7', 'd7ffff', 'ff0000', 'ff005f', 'ff0087', 'ff00af', 'ff00d7', 'ff00ff', 'ff5f00', 'ff5f5f', 'ff5f87', 'ff5faf', 'ff5fd7', 'ff5fff', 'ff8700', 'ff875f', 'ff8787', 'ff87af', 'ff87d7', 'ff87ff', 'ffaf00', 'ffaf5f', 'ffaf87', 'ffafaf', 'ffafd7', 'ffafff', 'ffd700', 'ffd75f', 'ffd787', 'ffd7af', 'ffd7d7', 'ffd7ff', 'ffff00', 'ffff5f', 'ffff87', 'ffffaf', 'ffffd7', 'ffffff', '000000', '121212', '1c1c1c', '262626', '303030', '3a3a3a', '444444', '4e4e4e', '585858', '626262', '6c6c6c', '767676', '808080', '8a8a8a', '949494', '9e9e9e', 'a8a8a8', 'b2b2b2', 'bcbcbc', 'c6c6c6', 'd0d0d0', 'dadada']

A table of 256 foreground or background colors.

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:
  1. 2011-2012 by Selectel.
copyright:

(c) 2012-2016 by pyte authors and contributors, see AUTHORS for details.

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 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\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.