Skip to content

Commit f255927

Browse files
Improved documentation.
1 parent 3d944a4 commit f255927

File tree

20 files changed

+275
-248
lines changed

20 files changed

+275
-248
lines changed

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Table of contents
7777
pages/asking_for_input
7878
pages/dialogs
7979
pages/full_screen_apps
80-
pages/architecture
8180
pages/advanced_topics/index
8281
pages/reference
8382

docs/pages/advanced_topics/filters.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ time. For instance:
1010
- to specify whether a part of the layout needs to be visible or not;
1111
- or to decide whether a certain key binding needs to be active or not;
1212
- or the ``wrap_lines`` option of
13-
:class:`~prompt_toolkit.layout.controls.BufferControl`;
13+
:class:`~prompt_toolkit.layout.BufferControl`;
1414
- etcetera.
1515

1616
These booleans are often dynamic and can change at runtime. For instance, the

docs/pages/advanced_topics/input_hooks.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33

44
Input hooks
55
-----------
6+
7+
Input hooks are a tool for inserting an external event loop into the
8+
prompt_toolkit event loop, so that the other loop can run as long as
9+
prompt_toolkit is idle. This is used in applications like `IPython
10+
<https://ipython.org/>`_, so that GUI toolkits can display their windows while
11+
we wait at the prompt for user input.

docs/pages/advanced_topics/rendering_flow.rst

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ The rendering flow
44
------------------
55

66
Understanding the rendering flow is important for understanding how
7-
:class:`~prompt_toolkit.layout.containers.Container` and
8-
:class:`~prompt_toolkit.layout.controls.UIControl` objects interact. We will
9-
demonstrate it by explaining the flow around a
10-
:class:`~prompt_toolkit.layout.controls.BufferControl`.
7+
:class:`~prompt_toolkit.layout.Container` and
8+
:class:`~prompt_toolkit.layout.UIControl` objects interact. We will demonstrate
9+
it by explaining the flow around a
10+
:class:`~prompt_toolkit.layout.BufferControl`.
1111

1212
.. note::
1313

14-
A :class:`~prompt_toolkit.layout.controls.BufferControl` is a
15-
:class:`~prompt_toolkit.layout.controls.UIControl` for displaying the
16-
content of a :class:`~prompt_toolkit.buffer.Buffer`. A buffer is the object
17-
that holds any editable region of text. Like all controls, it has to be
18-
wrapped into a :class:`~prompt_toolkit.layout.containers.Window`.
14+
A :class:`~prompt_toolkit.layout.BufferControl` is a
15+
:class:`~prompt_toolkit.layout.UIControl` for displaying the content of a
16+
:class:`~prompt_toolkit.buffer.Buffer`. A buffer is the object that holds
17+
any editable region of text. Like all controls, it has to be wrapped into a
18+
:class:`~prompt_toolkit.layout.Window`.
1919

2020
Let's take the following code:
2121

@@ -30,26 +30,26 @@ Let's take the following code:
3030
Window(content=BufferControl(buffer=b))
3131
3232
What happens when a :class:`~prompt_toolkit.renderer.Renderer` objects wants a
33-
:class:`~prompt_toolkit.layout.containers.Container` to be rendered on a
34-
certain :class:`~prompt_toolkit.layout.screen.Screen`?
33+
:class:`~prompt_toolkit.layout.Container` to be rendered on a certain
34+
:class:`~prompt_toolkit.layout.screen.Screen`?
3535

3636
The visualisation happens in several steps:
3737

3838
1. The :class:`~prompt_toolkit.renderer.Renderer` calls the
39-
:meth:`~prompt_toolkit.layout.containers.Container.write_to_screen` method
40-
of a :class:`~prompt_toolkit.layout.containers.Container`.
39+
:meth:`~prompt_toolkit.layout.Container.write_to_screen` method
40+
of a :class:`~prompt_toolkit.layout.Container`.
4141
This is a request to paint the layout in a rectangle of a certain size.
4242

43-
The :class:`~prompt_toolkit.layout.containers.Window` object then requests
44-
the :class:`~prompt_toolkit.layout.controls.UIControl` to create a
45-
:class:`~prompt_toolkit.layout.controls.UIContent` instance (by calling
46-
:meth:`~prompt_toolkit.layout.controls.UIControl.create_content`).
43+
The :class:`~prompt_toolkit.layout.Window` object then requests
44+
the :class:`~prompt_toolkit.layout.UIControl` to create a
45+
:class:`~prompt_toolkit.layout.UIContent` instance (by calling
46+
:meth:`~prompt_toolkit.layout.UIControl.create_content`).
4747
The user control receives the dimensions of the window, but can still
4848
decide to create more or less content.
4949

50-
Inside the :meth:`~prompt_toolkit.layout.controls.UIControl.create_content`
51-
method of :class:`~prompt_toolkit.layout.controls.UIControl`, there are
52-
several steps:
50+
Inside the :meth:`~prompt_toolkit.layout.UIControl.create_content`
51+
method of :class:`~prompt_toolkit.layout.UIControl`, there are several
52+
steps:
5353

5454
2. First, the buffer's text is passed to the
5555
:meth:`~prompt_toolkit.lexers.Lexer.lex_document` method of a
@@ -62,24 +62,24 @@ The visualisation happens in several steps:
6262
Each processor can do a transformation for each line.
6363
(For instance, they can insert or replace some text.)
6464

65-
4. The :class:`~prompt_toolkit.layout.controls.UIControl` returns a
66-
:class:`~prompt_toolkit.layout.controls.UIContent` instance which
65+
4. The :class:`~prompt_toolkit.layout.UIControl` returns a
66+
:class:`~prompt_toolkit.layout.UIContent` instance which
6767
generates such a token lists for each lines.
6868

69-
The :class:`~prompt_toolkit.layout.containers.Window` receives the
70-
:class:`~prompt_toolkit.layout.controls.UIContent` and then:
69+
The :class:`~prompt_toolkit.layout.Window` receives the
70+
:class:`~prompt_toolkit.layout.UIContent` and then:
7171

7272
5. It calculates the horizontal and vertical scrolling, if applicable
7373
(if the content would take more space than what is available).
7474

7575
6. The content is copied to the correct absolute position
7676
:class:`~prompt_toolkit.layout.screen.Screen`, as requested by the
7777
:class:`~prompt_toolkit.renderer.Renderer`. While doing this, the
78-
:class:`~prompt_toolkit.layout.containers.Window` can possible wrap the
78+
:class:`~prompt_toolkit.layout.Window` can possible wrap the
7979
lines, if line wrapping was configured.
8080

8181
Note that this process is lazy: if a certain line is not displayed in the
82-
:class:`~prompt_toolkit.layout.containers.Window`, then it is not requested
83-
from the :class:`~prompt_toolkit.layout.controls.UIContent`. And from there,
84-
the line is not passed through the processors or even asked from the
82+
:class:`~prompt_toolkit.layout.Window`, then it is not requested
83+
from the :class:`~prompt_toolkit.layout.UIContent`. And from there, the line is
84+
not passed through the processors or even asked from the
8585
:class:`~prompt_toolkit.lexers.Lexer`.

docs/pages/advanced_topics/styling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ for instance copy the following into your `.bashrc` file.
282282
# export PROMPT_TOOLKIT_COLOR_DEPTH=DEPTH_24_BIT
283283
284284
An application can also decide to set the color depth manually by passing a
285-
:class:`~prompt_toolkit.output.color_depth.ColorDepth` value to the
285+
:class:`~prompt_toolkit.output.ColorDepth` value to the
286286
:class:`~prompt_toolkit.application.Application` object:
287287

288288
.. code:: python

docs/pages/full_screen_apps.rst

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -98,47 +98,45 @@ customizable you want things to be. In fact, there are several layers of
9898
abstraction.
9999

100100
- The most low-level way of creating a layout is by combining
101-
:class:`~prompt_toolkit.layout.containers.Container` and
102-
:class:`~prompt_toolkit.layout.controls.UIControl` objects.
103-
104-
Examples of :class:`~prompt_toolkit.layout.containers.Container` objects are
105-
:class:`~prompt_toolkit.layout.containers.VSplit` (vertical split),
106-
:class:`~prompt_toolkit.layout.containers.HSplit` (horizontal split) and
107-
:class:`~prompt_toolkit.layout.containers.FloatContainer`. These containers
108-
arrange the layout and can split it in multiple regions. Each container can
109-
recursively contain multiple other containers. They can be combined in any
110-
way to define the "shape" of the layout.
111-
112-
The :class:`~prompt_toolkit.layout.containers.Window` object is a special
113-
kind of container that can contain a
114-
:class:`~prompt_toolkit.layout.controls.UIControl` object. The
115-
:class:`~prompt_toolkit.layout.controls.UIControl` object is responsible for
116-
the generation of the actual content. The
117-
:class:`~prompt_toolkit.layout.containers.Window` object acts as an adaptor
118-
between the :class:`~prompt_toolkit.layout.controls.UIControl` and other
119-
containers, but it's also responsible for the scrolling and line wrapping of
120-
the content.
121-
122-
Examples of :class:`~prompt_toolkit.layout.controls.UIControl` objects are
123-
:class:`~prompt_toolkit.layout.controls.BufferControl` for showing the
124-
content of an editable/scrollable buffer, and
125-
:class:`~prompt_toolkit.layout.controls.FormattedTextControl` for displaying
101+
:class:`~prompt_toolkit.layout.Container` and
102+
:class:`~prompt_toolkit.layout.UIControl` objects.
103+
104+
Examples of :class:`~prompt_toolkit.layout.Container` objects are
105+
:class:`~prompt_toolkit.layout.VSplit` (vertical split),
106+
:class:`~prompt_toolkit.layout.HSplit` (horizontal split) and
107+
:class:`~prompt_toolkit.layout.FloatContainer`. These containers arrange the
108+
layout and can split it in multiple regions. Each container can recursively
109+
contain multiple other containers. They can be combined in any way to define
110+
the "shape" of the layout.
111+
112+
The :class:`~prompt_toolkit.layout.Window` object is a special kind of
113+
container that can contain a :class:`~prompt_toolkit.layout.UIControl`
114+
object. The :class:`~prompt_toolkit.layout.UIControl` object is responsible
115+
for the generation of the actual content. The
116+
:class:`~prompt_toolkit.layout.Window` object acts as an adaptor between the
117+
:class:`~prompt_toolkit.layout.UIControl` and other containers, but it's also
118+
responsible for the scrolling and line wrapping of the content.
119+
120+
Examples of :class:`~prompt_toolkit.layout.UIControl` objects are
121+
:class:`~prompt_toolkit.layout.BufferControl` for showing the content of an
122+
editable/scrollable buffer, and
123+
:class:`~prompt_toolkit.layout.FormattedTextControl` for displaying
126124
(:ref:`formatted <formatted_text>`) text.
127125

128126
Normally, it is never needed to create new
129-
:class:`~prompt_toolkit.layout.controls.UIControl` or
130-
:class:`~prompt_toolkit.layout.containers.Container` classes, but instead you
131-
would create the layout by composing instances of the existing built-ins.
127+
:class:`~prompt_toolkit.layout.UIControl` or
128+
:class:`~prompt_toolkit.layout.Container` classes, but instead you would
129+
create the layout by composing instances of the existing built-ins.
132130

133131
- A higher level abstraction of building a layout is by using "widgets". A
134132
widget is a reusable layout component that can contain multiple containers
135133
and controls. It should have a ``__pt__container__`` function, which is
136134
supposed to return the root container for this widget. Prompt_toolkit
137135
contains a couple of widgets like
138-
:class:`~prompt_toolkit.widgets.base.TextArea`,
139-
:class:`~prompt_toolkit.widgets.base.Button`,
140-
:class:`~prompt_toolkit.widgets.base.Frame`,
141-
:class:`~prompt_toolkit.widgets.base.VerticalLine` and so on.
136+
:class:`~prompt_toolkit.widgets.TextArea`,
137+
:class:`~prompt_toolkit.widgets.Button`,
138+
:class:`~prompt_toolkit.widgets.Frame`,
139+
:class:`~prompt_toolkit.widgets.VerticalLine` and so on.
142140

143141
- The highest level abstractions can be found in the ``shortcuts`` module.
144142
There we don't have to think about the layout, controls and containers at
@@ -163,24 +161,23 @@ responsible for generating the actual content.
163161
content. A :class:`~prompt_toolkit.layout.controls.UIControl` is not aware
164162
of the screen.
165163

166-
+------------------------------------------------------+---------------------------------------------------------------+
167-
| Abstract base class | Examples |
168-
+======================================================+===============================================================+
169-
| :class:`~prompt_toolkit.layout.containers.Container` | :class:`~prompt_toolkit.layout.containers.HSplit` |
170-
| | :class:`~prompt_toolkit.layout.containers.VSplit` |
171-
| | :class:`~prompt_toolkit.layout.containers.FloatContainer` |
172-
| | :class:`~prompt_toolkit.layout.containers.Window` |
173-
+------------------------------------------------------+---------------------------------------------------------------+
174-
| :class:`~prompt_toolkit.layout.controls.UIControl` | :class:`~prompt_toolkit.layout.controls.BufferControl` |
175-
| | :class:`~prompt_toolkit.layout.controls.FormattedTextControl` |
176-
+------------------------------------------------------+---------------------------------------------------------------+
177-
178-
The :class:`~prompt_toolkit.layout.containers.Window` class itself is
179-
particular: it is a :class:`~prompt_toolkit.layout.containers.Container` that
180-
can contain a :class:`~prompt_toolkit.layout.controls.UIControl`. Thus, it's
181-
the adaptor between the two. The
182-
:class:`~prompt_toolkit.layout.containers.Window` class also takes care of
183-
scrolling the content and wrapping the lines if needed.
164+
+---------------------------------------------+------------------------------------------------------+
165+
| Abstract base class | Examples |
166+
+=============================================+======================================================+
167+
| :class:`~prompt_toolkit.layout.Container` | :class:`~prompt_toolkit.layout.HSplit` |
168+
| | :class:`~prompt_toolkit.layout.VSplit` |
169+
| | :class:`~prompt_toolkit.layout.FloatContainer` |
170+
| | :class:`~prompt_toolkit.layout.Window` |
171+
+---------------------------------------------+------------------------------------------------------+
172+
| :class:`~prompt_toolkit.layout.UIControl` | :class:`~prompt_toolkit.layout.BufferControl` |
173+
| | :class:`~prompt_toolkit.layout.FormattedTextControl` |
174+
+---------------------------------------------+------------------------------------------------------+
175+
176+
The :class:`~prompt_toolkit.layout.Window` class itself is
177+
particular: it is a :class:`~prompt_toolkit.layout.Container` that
178+
can contain a :class:`~prompt_toolkit.layout.UIControl`. Thus, it's the adaptor
179+
between the two. The :class:`~prompt_toolkit.layout.Window` class also takes
180+
care of scrolling the content and wrapping the lines if needed.
184181

185182
Finally, there is the :class:`~prompt_toolkit.layout.Layout` class which wraps
186183
the whole layout. This is responsible for keeping track of which window has the
@@ -222,9 +219,9 @@ vertical line:
222219
223220
224221
More complex layouts can be achieved by nesting multiple
225-
:class:`~prompt_toolkit.layout.containers.VSplit`,
226-
:class:`~prompt_toolkit.layout.containers.HSplit` and
227-
:class:`~prompt_toolkit.layout.containers.FloatContainer` objects.
222+
:class:`~prompt_toolkit.layout.VSplit`,
223+
:class:`~prompt_toolkit.layout.HSplit` and
224+
:class:`~prompt_toolkit.layout.FloatContainer` objects.
228225

229226
If you want to make some part of the layout only visible when a certain
230227
condition is satisfied, use a
@@ -236,7 +233,7 @@ Focusing windows
236233

237234
Focussing something can be done by calling the
238235
:meth:`~prompt_toolkit.layout.Layout.focus` method. This method is very
239-
flexible and accepts a :class:`~prompt_toolkit.layout.containers.Window`, a
236+
flexible and accepts a :class:`~prompt_toolkit.layout.Window`, a
240237
:class:`~prompt_toolkit.buffer.Buffer`, a
241238
:class:`~prompt_toolkit.layout.controls.UIControl` and more.
242239

@@ -269,9 +266,9 @@ There are two kinds of key bindings:
269266
- Key bindings that belong to a certain
270267
:class:`~prompt_toolkit.layout.controls.UIControl` and are only active when
271268
this control is focused. Both
272-
:class:`~prompt_toolkit.layout.controls.BufferControl`
273-
:class:`~prompt_toolkit.layout.controls.FormattedTextControl` take a
274-
``key_bindings`` argument.
269+
:class:`~prompt_toolkit.layout.BufferControl`
270+
:class:`~prompt_toolkit.layout.FormattedTextControl` take a ``key_bindings``
271+
argument.
275272

276273

277274
Global key bindings
@@ -319,8 +316,8 @@ named ``_`` (underscore) as well, because the we won't refer to this name.
319316
Modal containers
320317
^^^^^^^^^^^^^^^^
321318

322-
All container objects, like :class:`~prompt_toolkit.layout.containers.VSplit`
323-
and :class:`~prompt_toolkit.layout.containers.HSplit` take a ``modal`` argument.
319+
All container objects, like :class:`~prompt_toolkit.layout.VSplit` and
320+
:class:`~prompt_toolkit.layout.HSplit` take a ``modal`` argument.
324321

325322
If this flag has been set, then key bindings from the parent account are not
326323
taken into account if one of the children windows has the focus.
@@ -335,17 +332,17 @@ The global key bindings are always active.
335332
More about the Window class
336333
---------------------------
337334

338-
As said earlier, a :class:`~prompt_toolkit.layout.containers.Window` is a
339-
:class:`~prompt_toolkit.layout.containers.Container` that wraps a
340-
:class:`~prompt_toolkit.layout.controls.UIControl`, like a
341-
:class:`~prompt_toolkit.layout.controls.BufferControl` or
342-
:class:`~prompt_toolkit.layout.controls.FormattedTextControl`.
335+
As said earlier, a :class:`~prompt_toolkit.layout.Window` is a
336+
:class:`~prompt_toolkit.layout.Container` that wraps a
337+
:class:`~prompt_toolkit.layout.UIControl`, like a
338+
:class:`~prompt_toolkit.layout.BufferControl` or
339+
:class:`~prompt_toolkit.layout.FormattedTextControl`.
343340

344341
.. note::
345342

346343
Basically, windows are the leafs in the tree structure that represent the UI.
347344

348-
A :class:`~prompt_toolkit.layout.containers.Window` provides a "view" on the
345+
A :class:`~prompt_toolkit.layout.Window` provides a "view" on the
349346
:class:`~prompt_toolkit.layout.controls.UIControl`, which provides lines of
350347
content. The window is in the first place responsible for the line wrapping and
351348
scrolling of the content, but there are much more options.
@@ -359,18 +356,18 @@ scrolling of the content, but there are much more options.
359356
- Finally, the background can be filled with a default character.
360357

361358

362-
More about buffers and :class:`~prompt_toolkit.layout.controls.BufferControl`
363-
-----------------------------------------------------------------------------
359+
More about buffers and :class:`~prompt_toolkit.layout.BufferControl`
360+
--------------------------------------------------------------------
364361

365362

366363

367364
Input processors
368365
^^^^^^^^^^^^^^^^
369366

370367
A :class:`~prompt_toolkit.layout.processors.Processor` is used to postprocess
371-
the content of a :class:`~prompt_toolkit.layout.controls.BufferControl` before
372-
it's displayed. It can for instance highlight matching brackets or change
373-
the visualisation of tabs and so on.
368+
the content of a :class:`~prompt_toolkit.layout.BufferControl` before it's
369+
displayed. It can for instance highlight matching brackets or change the
370+
visualisation of tabs and so on.
374371

375372
A :class:`~prompt_toolkit.layout.processors.Processor` operates on individual
376373
lines. Basically, it takes a (formatted) line and produces a new (formatted)
@@ -402,6 +399,6 @@ Some build-in processors:
402399
| :class:`~prompt_toolkit.layout.processors.TabsProcessor` | Visualise tabs as `n` spaces, or some symbols. |
403400
+----------------------------------------------------------------------------+-----------------------------------------------------------+
404401

405-
A :class:`~prompt_toolkit.layout.controls.BufferControl` takes only one
406-
processor as input, but it is possible to "merge" multiple processors into one
407-
with the :func:`~prompt_toolkit.layout.processors.merge_processors` function.
402+
A :class:`~prompt_toolkit.layout.BufferControl` takes only one processor as
403+
input, but it is possible to "merge" multiple processors into one with the
404+
:func:`~prompt_toolkit.layout.processors.merge_processors` function.

0 commit comments

Comments
 (0)