-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
53 lines (40 loc) · 1.65 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
pyte
~~~~
`pyte` implements a mix of VT100, VT220 and VT520 specification,
and aims to support most of the `TERM=linux` functionality.
Two classes: :class:`~pyte.streams.Stream`, which parses the
command stream and dispatches events for commands, and
:class:`~pyte.screens.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: (c) 2011-2012 by Selectel.
:copyright: (c) 2012-2017 by pyte authors and contributors,
see AUTHORS for details.
:license: LGPL, see LICENSE for more details.
"""
from __future__ import absolute_import
__all__ = ("Screen", "DiffScreen", "HistoryScreen", "DebugScreen",
"Stream", "ByteStream")
import io
from .screens import Screen, DiffScreen, HistoryScreen, DebugScreen
from .streams import Stream, ByteStream
if __debug__:
from .compat import str
def dis(chars):
"""A :func:`dis.dis` for terminals.
>>> dis(b"\x07") # doctest: +NORMALIZE_WHITESPACE
["bell", [], {}]
>>> dis(b"\x1b[20m") # doctest: +NORMALIZE_WHITESPACE
["select_graphic_rendition", [20], {}]
"""
if isinstance(chars, str):
chars = chars.encode("utf-8")
with io.StringIO() as buf:
ByteStream(DebugScreen(to=buf)).feed(chars)
print(buf.getvalue())