summaryrefslogtreecommitdiffstats
path: root/docs/pages/advanced_topics/architecture.rst
blob: c690104d1f671c9b9b76b9103d995921c71f506e (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
.. _architecture:


Architecture
============

TODO: this is a little outdated.

::

    +---------------------------------------------------------------+
    |     InputStream                                               |
    |     ===========                                               |
    |          - Parses the input stream coming from a VT100        |
    |            compatible terminal. Translates it into data input |
    |            and control characters. Calls the corresponding    |
    |            handlers of the `InputStreamHandler` instance.     |
    |                                                               |
    |          e.g. Translate '\x1b[6~' into "Keys.PageDown", call  |
    |               the `feed_key` method of `InputProcessor`.      |
    +---------------------------------------------------------------+
               |
               v
    +---------------------------------------------------------------+
    |     InputStreamHandler                                        |
    |     ==================                                        |
    |          - Has a `Registry` of key bindings, it calls the     |
    |            bindings according to the received keys and the    |
    |            input mode.                                        |
    |                                                               |
    |         We have Vi and Emacs bindings.
    +---------------------------------------------------------------+
               |
               v
    +---------------------------------------------------------------+
    |     Key bindings                                              |
    |     ============                                              |
    |          - Every key binding consists of a function that      |
    |            receives an `Event` and usually it operates on     |
    |            the `Buffer` object. (It could insert data or      |
    |            move the cursor for example.)                      |
    +---------------------------------------------------------------+
        |
        | Most of the key bindings operate on a `Buffer` object, but
        | they don't have to. They could also change the visibility
        | of a menu for instance, or change the color scheme.
        |
        v
    +---------------------------------------------------------------+
    |     Buffer                                                    |
    |     ======                                                    |
    |          - Contains a data structure to hold the current      |
    |            input (text and cursor position). This class       |
    |            implements all text manipulations and cursor       |
    |            movements (Like e.g. cursor_forward, insert_char   |
    |            or delete_word.)                                   |
    |                                                               |
    |            +-----------------------------------------------+  |
    |            | Document (text, cursor_position)              |  |
    |            | ================================              |  |
    |            | Accessed as the `document` property of the    |  |
    |            | `Buffer` class. This is a wrapper around the  |  |
    |            | text and cursor position, and contains        |  |
    |            | methods for querying this data , e.g. to give |  |
    |            | the text before the cursor.                   |  |
    |            +-----------------------------------------------+  |
    +---------------------------------------------------------------+
        |
        |  Normally after every key press, the output will be
        |  rendered again. This happens in the event loop of
        |  the `Application` where `Renderer.render` is called.
        v
    +---------------------------------------------------------------+
    |     Layout                                                    |
    |     ======                                                    |
    |          - When the renderer should redraw, the renderer      |
    |            asks the layout what the output should look like.  |
    |          - The layout operates on a `Screen` object that he   |
    |            received from the `Renderer` and will put the      |
    |            toolbars, menus, highlighted content and prompt    |
    |            in place.                                          |
    |                                                               |
    |            +-----------------------------------------------+  |
    |            | Menus, toolbars, prompt                       |  |
    |            | =======================                       |  |
    |            |                                               |  |
    |            +-----------------------------------------------+  |
    +---------------------------------------------------------------+
        |
        v
    +---------------------------------------------------------------+
    |     Renderer                                                  |
    |     ========                                                  |
    |          - Calculates the difference between the last output  |
    |            and the new one and writes it to the terminal      |
    |            output.                                            |
    +---------------------------------------------------------------+