File: tutorial.rst

package info (click to toggle)
pyte 0.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: python: 3,167; makefile: 11
file content (58 lines) | stat: -rw-r--r-- 3,519 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
.. _tutorial:

Tutorial
--------

There are two important classes in ``pyte``: :class:`~pyte.screens.Screen`
and :class:`~pyte.streams.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 :ref:`API reference <api>` for more
details.

In general, if you just want to know what's being displayed on screen you
can do something like the following:

    >>> from __future__ import unicode_literals
    >>> import pyte
    >>> screen = pyte.Screen(80, 24)
    >>> stream = pyte.Stream(screen)
    >>> stream.feed(b"Hello World!")
    >>> screen.display
        ['Hello World!                                                                    ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ',
         '                                                                                ']


**Note**: ``Screen`` has no idea what is the source of bytes 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
<https://github.com/selectel/pyte/examples>`_ for  more.