Skip to content

Commit 2c90917

Browse files
More documentation.
1 parent ccc4ceb commit 2c90917

File tree

8 files changed

+63
-50
lines changed

8 files changed

+63
-50
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ Changes:
134134
passed to the `Window` class and applied to the content as well.
135135
* Alignment of the content is now done in the `Window` class, not in the
136136
user control.
137+
* The continuation function of `PromptMargin` now takes `line_number` and
138+
* `is_soft_wrap` as input.
137139

138140
- Changes to `BufferControl`:
139141

@@ -178,6 +180,11 @@ Changes:
178180
wait for all the completions to be generated, before displaying the first
179181
one. The completion menus are updated as soon as new completions arrive.
180182

183+
- Changes regarding the `History` classes:
184+
185+
* The `History` base class has a different interface. This was needed for
186+
asynchronous loading of the history. `ThreadedHistory` was added for this.
187+
181188
- Changes related to `shortcuts.prompt`:
182189

183190
* There is now a class `Prompt` which also has a method `prompt`. Both the

docs/pages/advanced_topics/filters.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,4 @@ instance, and always returns a :class:`~prompt_toolkit.filters.Filter`.
166166
f = to_filter(True)
167167
f = to_filter(False)
168168
f = to_filter(Condition(lambda: True))
169+
f = to_filter(has_search | has_selection)

docs/pages/asking_for_input.rst

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,15 @@ Auto suggestion is a way to propose some input completions to the user like the
457457

458458
Usually, the input is compared to the history and when there is another entry
459459
starting with the given text, the completion will be shown as gray text behind
460-
the current input. Pressing the right arrow :kbd:`` will insert this suggestion.
460+
the current input. Pressing the right arrow :kbd:`` or :kbd:`c-e` will insert
461+
this suggestion, :kbd:`alt-f` will insert the first word of the suggestion.
461462

462463
.. note::
463464

464465
When suggestions are based on the history, don't forget to share one
465466
:class:`~prompt_toolkit.history.History` object between consecutive
466467
:func:`~prompt_toolkit.shortcuts.prompt` calls. Using a
467-
:class:`~prompt_toolkit.prompt.PromptSession` does this for you.
468+
:class:`~prompt_toolkit.shortcuts.PromptSession` does this for you.
468469

469470
Example:
470471

@@ -489,12 +490,15 @@ passed as an argument.
489490
Adding a bottom toolbar
490491
-----------------------
491492

492-
Adding a bottom toolbar is as easy as passing a ``bottom_toolbar`` function to
493-
:func:`~prompt_toolkit.shortcuts.prompt`. The function is called every time the
494-
prompt is rendered (at least on every key stroke), so the bottom toolbar can be
495-
used to display dynamic information. It should return formatted text or a list
496-
of ``(style, text)`` tuples. The toolbar is always erased when the prompt
497-
returns.
493+
Adding a bottom toolbar is as easy as passing a ``bottom_toolbar`` argument to
494+
:func:`~prompt_toolkit.shortcuts.prompt`. This argument be either plain text,
495+
:ref:`formatted text <formatted_text>` or a callable that returns plain or
496+
formatted text.
497+
498+
When a function is given, it will be called every time the prompt is rendered,
499+
so the bottom toolbar can be used to display dynamic information.
500+
501+
The toolbar is always erased when the prompt returns.
498502

499503
.. code:: python
500504
@@ -516,14 +520,17 @@ the background of the toolbar.
516520

517521
.. image:: ../images/bottom-toolbar.png
518522

523+
519524
Adding a right prompt
520525
---------------------
521526

522527
The :func:`~prompt_toolkit.shortcuts.prompt` function has out of the box
523528
support for right prompts as well. People familiar to ZSH could recognise this
524529
as the `RPROMPT` option.
525530

526-
So, similar to adding a bottom toolbar, we can pass a ``get_rprompt`` callable.
531+
So, similar to adding a bottom toolbar, we can pass an ``rprompt`` argument.
532+
This can be either plain text, :ref:`formatted text <formatted_text>` or a
533+
callable which returns either.
527534

528535
.. code:: python
529536
@@ -585,17 +592,25 @@ An example of a prompt that prints ``'hello world'`` when :kbd:`Control-T` is pr
585592
586593
@bindings.add('c-t')
587594
def _(event):
595+
" Say 'hello' when `c-t` is pressed. "
588596
def print_hello():
589597
print('hello world')
590598
run_in_terminal(print_hello)
591599
600+
@bindings.add('c-x')
601+
def _(event):
602+
" Exit when `c-x` is pressed. "
603+
event.app.exit()
604+
592605
text = prompt('> ', key_bindings=bindings)
593606
print('You said: %s' % text)
594607
595608
596609
Note that we use
597-
:meth:`~prompt_toolkit.application.run_in_terminal`. This
598-
ensures that the output of the print-statement and the prompt don't mix up.
610+
:meth:`~prompt_toolkit.application.run_in_terminal` for the first key binding.
611+
This ensures that the output of the print-statement and the prompt don't mix
612+
up. If the key bindings doesn't print anything, then it can be handled directly
613+
without nesting functions.
599614

600615

601616
Enable key bindings according to a condition

docs/pages/example.rst

Whitespace-only changes.

docs/pages/full_screen_apps.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ I/O objects
6767
Every :class:`~prompt_toolkit.application.Application` instance requires an I/O
6868
objects for input and output:
6969

70-
- An :class:`~prompt_toolkit.input.base.Input` instance, which is an
71-
abstraction of the input stream (stdin).
72-
- An :class:`~prompt_toolkit.output.base.Output` instance, which is an
70+
- An :class:`~prompt_toolkit.input.Input` instance, which is an abstraction
71+
of the input stream (stdin).
72+
- An :class:`~prompt_toolkit.output.Output` instance, which is an
7373
abstraction of the output stream, and is called by the renderer.
7474

7575
Both are optional and normally not needed to pass explicitly. Usually, the
7676
default works fine.
7777

7878
There is a third I/O object which is also required by the application, but not
7979
passed inside. This is the event loop, an
80-
:class:`~prompt_toolkit.eventloop.base.EventLoop` instance. This is basically a
80+
:class:`~prompt_toolkit.eventloop.EventLoop` instance. This is basically a
8181
while-true loop that waits for user input, and when it receives something (like
8282
a key press), it will send that to the the appropriate handler, like for
8383
instance, a key binding.
@@ -343,9 +343,9 @@ As said earlier, a :class:`~prompt_toolkit.layout.Window` is a
343343
Basically, windows are the leafs in the tree structure that represent the UI.
344344

345345
A :class:`~prompt_toolkit.layout.Window` provides a "view" on the
346-
:class:`~prompt_toolkit.layout.controls.UIControl`, which provides lines of
347-
content. The window is in the first place responsible for the line wrapping and
348-
scrolling of the content, but there are much more options.
346+
:class:`~prompt_toolkit.layout.UIControl`, which provides lines of content. The
347+
window is in the first place responsible for the line wrapping and scrolling of
348+
the content, but there are much more options.
349349

350350
- Adding left or right margins. These are used for displaying scroll bars or
351351
line numbers.

docs/pages/printing_text.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ You can replace the built in ``print`` function as follows, if you want to.
5959
Formatted text
6060
--------------
6161

62-
There are several ways to print colors:
62+
There are several ways to display colors:
6363

6464
- By creating an :class:`~prompt_toolkit.formatted_text.HTML` object.
6565
- By creating an :class:`~prompt_toolkit.formatted_text.ANSI` object that

docs/pages/reference.rst

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,6 @@ Controls
152152
FormattedTextControl, UIControl, UIContent
153153

154154

155-
Widgets
156-
^^^^^^^
157-
158-
.. automodule:: prompt_toolkit.widgets
159-
:members: TextArea, Label, Button, Frame, Shadow, Box, VerticalLine,
160-
HorizontalLine, RadioList, Checkbox, ProgressBar
161-
162-
.. automodule:: prompt_toolkit.widgets
163-
:members: ArgToolbar, CompletionsToolbar, FormattedTextToolbar,
164-
SearchToolbar, SystemToolbar, ValidationToolbar
165-
166-
.. automodule:: prompt_toolkit.widgets
167-
:members: Dialog, MenuContainer, MenuItem
168-
169-
170155
Other
171156
^^^^^
172157

@@ -185,6 +170,16 @@ Other
185170
:members:
186171

187172

173+
Widgets
174+
-------
175+
176+
.. automodule:: prompt_toolkit.widgets
177+
:members: TextArea, Label, Button, Frame, Shadow, Box, VerticalLine,
178+
HorizontalLine, RadioList, Checkbox, ProgressBar, CompletionsToolbar,
179+
FormattedTextToolbar, SearchToolbar, SystemToolbar, ValidationToolbar,
180+
MenuContainer, MenuItem
181+
182+
188183
Filters
189184
-------
190185

@@ -221,8 +216,12 @@ Key binding
221216
Eventloop
222217
---------
223218

224-
.. automodule:: prompt_toolkit.eventloop.base
225-
:members:
219+
.. automodule:: prompt_toolkit.eventloop
220+
:members: EventLoop, get_traceback_from_context, From, Return,
221+
ensure_future, create_event_loop, create_asyncio_event_loop,
222+
use_asyncio_event_loop, get_event_loop, set_event_loop,
223+
run_in_executor, call_from_executor, run_until_complete, Future,
224+
InvalidStateError
226225

227226
.. automodule:: prompt_toolkit.eventloop.posix
228227
:members:
@@ -236,21 +235,12 @@ Eventloop
236235
.. automodule:: prompt_toolkit.eventloop.asyncio_posix
237236
:members:
238237

239-
.. automodule:: prompt_toolkit.eventloop.coroutine
240-
:members:
241-
242-
.. automodule:: prompt_toolkit.eventloop.future
243-
:members:
244-
245238

246239
Input
247240
-----
248241

249242
.. automodule:: prompt_toolkit.input
250-
:members:
251-
252-
.. automodule:: prompt_toolkit.input.defaults
253-
:members:
243+
:members: Input, DummyInput, create_input, get_default_input, set_default_input
254244

255245
.. automodule:: prompt_toolkit.input.vt100
256246
:members:
@@ -262,10 +252,8 @@ Output
262252
------
263253

264254
.. automodule:: prompt_toolkit.output
265-
:members:
266-
267-
.. automodule:: prompt_toolkit.output.defaults
268-
:members:
255+
:members: Output, DummyOutput, ColorDepth, create_output,
256+
get_default_output, set_default_output
269257

270258
.. automodule:: prompt_toolkit.output.vt100
271259
:members:

prompt_toolkit/shortcuts/prompt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ class PromptSession(object):
202202
:param history: :class:`~prompt_toolkit.history.History` instance.
203203
:param clipboard: :class:`~prompt_toolkit.clipboard.Clipboard` instance.
204204
(e.g. :class:`~prompt_toolkit.clipboard.InMemoryClipboard`)
205+
:param rprompt: Text or formatted text to be displayed on the right side.
206+
This can also be a callable that returns (formatted) text.
205207
:param bottom_toolbar: Formatted text or callable which is supposed to
206208
return formatted text.
207209
:param prompt_continuation: Text that needs to be displayed for a multiline

0 commit comments

Comments
 (0)