Adding upstream version 3.0.46.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-12 17:47:49 +02:00
parent a8b5c9264a
commit f9d8bce83f
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
218 changed files with 513 additions and 322 deletions

View file

@ -1,6 +1,33 @@
CHANGELOG
=========
3.0.46: 2024-06-04
------------------
Fixes:
- Fix pytest capsys fixture compatibility.
3.0.45: 2024-05-28
------------------
Fixes:
- Improve performance of `GrammarCompleter` (faster deduplication of completions).
3.0.44: 2024-05-27
------------------
New features:
- Accept `os.PathLike` in `FileHistory` (typing fix).
Fixes:
- Fix memory leak in filters.
- Improve performance of progress bar formatters.
- Fix compatibility when a SIGINT handler is installed by non-Python (Rust, C).
- Limit number of completions in buffer to 10k by default (for performance).
3.0.43: 2023-12-13
------------------

View file

@ -39,6 +39,7 @@ Shells:
- `kafka-shell <https://github.com/devshawn/kafka-shell>`_: A supercharged shell for Apache Kafka.
- `starterTree <https://github.com/thomas10-10/starterTree>`_: A command launcher organized in a tree structure with fuzzy autocompletion
- `git-delete-merged-branches <https://github.com/hartwork/git-delete-merged-branches>`_: Command-line tool to delete merged Git branches
- `radian <https://github.com/randy3k/radian>`_: A 21 century R console
Full screen applications:
@ -51,6 +52,7 @@ Full screen applications:
- `sanctuary-zero <https://github.com/t0xic0der/sanctuary-zero>`_: A secure chatroom with zero logging and total transience.
- `Hummingbot <https://github.com/CoinAlpha/hummingbot>`_: A Cryptocurrency Algorithmic Trading Platform
- `git-bbb <https://github.com/MrMino/git-bbb>`_: A `git blame` browser.
- `ass <https://github.com/mlang/ass`_: An OpenAI Assistants API client.
Libraries:

View file

@ -80,8 +80,6 @@ It's worth noting that the implementation is a "best effort of what is
possible". Both Unix and Windows terminals have their limitations. But in
general, the Unix experience will still be a little better.
For Windows, it's recommended to use either `cmder
<http://cmder.net/>`_ or `conemu <https://conemu.github.io/>`_.
Getting started
***************

View file

@ -41,16 +41,16 @@ master_doc = "index"
# General information about the project.
project = "prompt_toolkit"
copyright = "2014-2023, Jonathan Slenders"
copyright = "2014-2024, Jonathan Slenders"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = "3.0.43"
version = "3.0.46"
# The full version, including alpha/beta/rc tags.
release = "3.0.43"
release = "3.0.46"
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View file

@ -116,6 +116,21 @@ single fixture that does it for every test. Something like this:
with create_app_session(input=pipe_input, output=DummyOutput()):
yield pipe_input
For compatibility with pytest's ``capsys`` fixture, we have to create a new
:class:`~prompt_toolkit.application.current.AppSession` for every test. This
can be done in an autouse fixture. Pytest replaces ``sys.stdout`` with a new
object in every test that uses ``capsys`` and the following will ensure that
the new :class:`~prompt_toolkit.application.current.AppSession` will each time
refer to the latest output.
.. code:: python
from prompt_toolkit.application import create_app_session
@fixture(autouse=True, scope="function")
def _pt_app_session()
with create_app_session():
yield
Type checking
-------------

View file

@ -358,7 +358,7 @@ As said earlier, a :class:`~prompt_toolkit.layout.Window` is a
.. note::
Basically, windows are the leafs in the tree structure that represent the UI.
Basically, windows are the leaves in the tree structure that represent the UI.
A :class:`~prompt_toolkit.layout.Window` provides a "view" on the
:class:`~prompt_toolkit.layout.UIControl`, which provides lines of content. The
@ -391,7 +391,7 @@ A :class:`~prompt_toolkit.layout.processors.Processor` operates on individual
lines. Basically, it takes a (formatted) line and produces a new (formatted)
line.
Some build-in processors:
Some built-in processors:
+----------------------------------------------------------------------------+-----------------------------------------------------------+
| Processor | Usage: |

View file

@ -237,7 +237,7 @@ printing text possible while the progress bar is displayed. This ensures that
printing happens above the progress bar.
Further, when "x" is pressed, we set a cancel flag, which stops the progress.
It would also be possible to send `SIGINT` to the mean thread, but that's not
It would also be possible to send `SIGINT` to the main thread, but that's not
always considered a clean way of cancelling something.
In the example above, we also display a toolbar at the bottom which shows the

View file

@ -2,6 +2,7 @@
"""
Example of button dialog window.
"""
from prompt_toolkit.shortcuts import button_dialog

View file

@ -2,6 +2,7 @@
"""
Example of a checkbox-list-based dialog.
"""
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import checkboxlist_dialog, message_dialog
from prompt_toolkit.styles import Style
@ -30,7 +31,7 @@ results = checkboxlist_dialog(
if results:
message_dialog(
title="Room service",
text="You selected: %s\nGreat choice sir !" % ",".join(results),
text="You selected: {}\nGreat choice sir !".format(",".join(results)),
).run()
else:
message_dialog("*starves*").run()

View file

@ -2,6 +2,7 @@
"""
Example of an input box dialog.
"""
from prompt_toolkit.shortcuts import input_dialog

View file

@ -2,6 +2,7 @@
"""
Example of a message box window.
"""
from prompt_toolkit.shortcuts import message_dialog

View file

@ -2,6 +2,7 @@
"""
Example of an password input dialog.
"""
from prompt_toolkit.shortcuts import input_dialog

View file

@ -2,6 +2,7 @@
"""
Example of a progress bar dialog.
"""
import os
import time

View file

@ -2,6 +2,7 @@
"""
Example of a radio list box dialog.
"""
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import radiolist_dialog

View file

@ -7,6 +7,7 @@ styling.
This also demonstrates that the `title` argument can be any kind of formatted
text.
"""
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import message_dialog
from prompt_toolkit.styles import Style

View file

@ -2,6 +2,7 @@
"""
Example of confirmation (yes/no) dialog window.
"""
from prompt_toolkit.shortcuts import yes_no_dialog

View file

@ -2,6 +2,7 @@
"""
A simple example of a few buttons and click handlers.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import get_app
from prompt_toolkit.key_binding import KeyBindings

View file

@ -3,6 +3,7 @@
A simple example of a calculator program.
This could be used as inspiration for a REPL.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.document import Document
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
This is the most simple example possible.
"""
from prompt_toolkit import Application
app = Application(full_screen=False)

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
"""
"""
""" """
from pygments.lexers.html import HtmlLexer
from prompt_toolkit.application import Application
@ -218,7 +218,7 @@ application = Application(
def run():
result = application.run()
print("You said: %r" % result)
print(f"You said: {result!r}")
if __name__ == "__main__":

View file

@ -2,6 +2,7 @@
"""
A simple example of a a text area displaying "Hello World!".
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout import Layout

View file

@ -2,6 +2,7 @@
"""
An empty full screen application without layout.
"""
from prompt_toolkit import Application
Application(full_screen=True).run()

View file

@ -2,6 +2,7 @@
"""
A simple application that shows a Pager application.
"""
from pygments.lexers.python import PythonLexer
from prompt_toolkit.application import Application
@ -28,10 +29,7 @@ def get_statusbar_text():
("class:status", _pager_py_path + " - "),
(
"class:status.position",
"{}:{}".format(
text_area.document.cursor_position_row + 1,
text_area.document.cursor_position_col + 1,
),
f"{text_area.document.cursor_position_row + 1}:{text_area.document.cursor_position_col + 1}",
),
("class:status", " - Press "),
("class:status.key", "Ctrl-C"),

View file

@ -2,6 +2,7 @@
"""
A simple example of a scrollable pane.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import get_app
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
A simple example of a scrollable pane.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import get_app
from prompt_toolkit.completion import WordCompleter

View file

@ -2,6 +2,7 @@
"""
Demo of the different Window alignment options.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import HSplit, Window, WindowAlign

View file

@ -6,6 +6,7 @@ completion.
Important is to make sure that there is a `CompletionsMenu` in the layout,
otherwise the completions won't be visible.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.completion import WordCompleter

View file

@ -2,6 +2,7 @@
"""
Colorcolumn example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
Cursorcolumn / cursorline example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
Example of the 'transparency' attribute of `Window' when used in a Float.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
Horizontal split example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import Float, FloatContainer, Window

View file

@ -2,6 +2,7 @@
"""
Demonstration of how to programmatically focus a certain widget.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.document import Document

View file

@ -2,6 +2,7 @@
"""
Horizontal align demo with HSplit.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
Horizontal split example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import HSplit, Window

View file

@ -6,6 +6,7 @@ completion.
Important is to make sure that there is a `CompletionsMenu` in the layout,
otherwise the completions won't be visible.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.filters import Condition

View file

@ -5,6 +5,7 @@ Example of Window margins.
This is mainly used for displaying line numbers and scroll bars, but it could
be used to display any other kind of information as well.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
Vertical align demo with VSplit.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
Vertical split example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import VSplit, Window

View file

@ -5,6 +5,7 @@ Simple example of a full screen application with a vertical split.
This will show a window on the left for user input. When the user types, the
reversed input is shown on the right. Pressing Ctrl-Q will quit the application.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings

View file

@ -2,6 +2,7 @@
"""
A simple example of a Notepad-like text editor.
"""
import datetime
from asyncio import Future, ensure_future
@ -53,10 +54,7 @@ def get_statusbar_text():
def get_statusbar_right_text():
return " {}:{} ".format(
text_field.document.cursor_position_row + 1,
text_field.document.cursor_position_col + 1,
)
return f" {text_field.document.cursor_position_row + 1}:{text_field.document.cursor_position_col + 1} "
search_toolbar = SearchToolbar()

View file

@ -3,6 +3,7 @@
For testing: test to make sure that everything still works when gevent monkey
patches are applied.
"""
from gevent.monkey import patch_all
from prompt_toolkit.eventloop.defaults import create_event_loop
@ -21,4 +22,4 @@ if __name__ == "__main__":
# Ask for input.
session = PromptSession("Give me some input: ", loop=eventloop)
answer = session.prompt()
print("You said: %s" % answer)
print(f"You said: {answer}")

View file

@ -2,6 +2,7 @@
"""
Demonstration of all the ANSI colors.
"""
from prompt_toolkit import print_formatted_text
from prompt_toolkit.formatted_text import HTML, FormattedText

View file

@ -5,6 +5,7 @@ Demonstration of how to print using ANSI escape sequences.
The advantage here is that this is cross platform. The escape sequences will be
parsed and turned into appropriate Win32 API calls on Windows.
"""
from prompt_toolkit import print_formatted_text
from prompt_toolkit.formatted_text import ANSI, HTML

View file

@ -2,6 +2,7 @@
"""
Demonstration of how to print using the HTML class.
"""
from prompt_toolkit import HTML, print_formatted_text
print = print_formatted_text

View file

@ -2,6 +2,7 @@
"""
Demonstration of all the ANSI colors.
"""
from prompt_toolkit import HTML, print_formatted_text
from prompt_toolkit.formatted_text import FormattedText
from prompt_toolkit.output import ColorDepth

View file

@ -2,6 +2,7 @@
"""
Example of printing colored text to the output.
"""
from prompt_toolkit import print_formatted_text
from prompt_toolkit.formatted_text import ANSI, HTML, FormattedText
from prompt_toolkit.styles import Style

View file

@ -3,6 +3,7 @@
Example usage of 'print_container', a tool to print
any layout in a non-interactive way.
"""
from prompt_toolkit.shortcuts import print_container
from prompt_toolkit.widgets import Frame, TextArea

View file

@ -4,6 +4,7 @@ This prints the prompt_toolkit logo at the terminal.
The ANSI output was generated using "pngtoansi": https://github.com/crgimenes/pngtoansi
(ESC still had to be replaced with \x1b
"""
from prompt_toolkit import print_formatted_text
from prompt_toolkit.formatted_text import ANSI

View file

@ -3,6 +3,7 @@
Printing a list of Pygments (Token, text) tuples,
or an output of a Pygments lexer.
"""
import pygments
from pygments.lexers.python import PythonLexer
from pygments.token import Token

View file

@ -2,6 +2,7 @@
"""
Demonstration of all the ANSI colors.
"""
from prompt_toolkit import print_formatted_text
from prompt_toolkit.formatted_text import HTML, FormattedText
from prompt_toolkit.output import ColorDepth

View file

@ -2,6 +2,7 @@
"""
More complex demonstration of what's possible with the progress bar.
"""
import random
import threading
import time

View file

@ -3,6 +3,7 @@
A progress bar that displays a formatted title above the progress bar and has a
colored label.
"""
import time
from prompt_toolkit.formatted_text import HTML

View file

@ -3,6 +3,7 @@
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import os
import signal
import time

View file

@ -2,6 +2,7 @@
"""
More complex demonstration of what's possible with the progress bar.
"""
import threading
import time

View file

@ -2,6 +2,7 @@
"""
Example of nested progress bars.
"""
import time
from prompt_toolkit import HTML

View file

@ -3,6 +3,7 @@
A very simple progress bar where the name of the task scrolls, because it's too long.
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar

View file

@ -3,6 +3,7 @@
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar

View file

@ -3,6 +3,7 @@
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar

View file

@ -3,6 +3,7 @@
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.formatted_text import HTML

View file

@ -2,6 +2,7 @@
"""
Styled just like an apt-get installation.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar

View file

@ -2,6 +2,7 @@
"""
A simple progress bar, visualized with rainbow colors (for fun).
"""
import time
from prompt_toolkit.output import ColorDepth

View file

@ -4,6 +4,7 @@ Styled similar to tqdm, another progress bar implementation in Python.
See: https://github.com/noamraph/tqdm
"""
import time
from prompt_toolkit.shortcuts import ProgressBar

View file

@ -4,6 +4,7 @@ Styled similar to tqdm, another progress bar implementation in Python.
See: https://github.com/noamraph/tqdm
"""
import time
from prompt_toolkit.shortcuts import ProgressBar

View file

@ -2,6 +2,7 @@
"""
Two progress bars that run in parallel.
"""
import threading
import time

View file

@ -3,6 +3,7 @@
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar

View file

@ -6,6 +6,7 @@ user typed without allowing him/her to edit it.
This should display the prompt with all the formatting like usual, but not
allow any editing.
"""
from prompt_toolkit import HTML, prompt
if __name__ == "__main__":
@ -13,4 +14,4 @@ if __name__ == "__main__":
HTML("<b>Type <u>some input</u>: </b>"), accept_default=True, default="test"
)
print("You said: %s" % answer)
print(f"You said: {answer}")

View file

@ -2,6 +2,7 @@
"""
Example of using the control-space key binding for auto completion.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.key_binding import KeyBindings
@ -68,7 +69,7 @@ def main():
complete_while_typing=False,
key_bindings=kb,
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -3,6 +3,7 @@
Autocompletion example that displays the autocompletions like readline does by
binding a custom handler to the Tab key.
"""
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import CompleteStyle, prompt
@ -51,7 +52,7 @@ def main():
completer=animal_completer,
complete_style=CompleteStyle.READLINE_LIKE,
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -7,6 +7,7 @@ Press [Tab] to complete the current word.
and shows all the completions. (In the menu)
- Any following tab press cycles through all the possible completions.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
@ -53,7 +54,7 @@ def main():
text = prompt(
"Give some animals: ", completer=animal_completer, complete_while_typing=False
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -4,6 +4,7 @@ Demonstration of a custom completer class and the possibility of styling
completions independently by passing formatted text objects to the "display"
and "display_meta" arguments of "Completion".
"""
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import CompleteStyle, prompt

View file

@ -3,6 +3,7 @@
Demonstration of a custom completer class and the possibility of styling
completions independently.
"""
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.output.color_depth import ColorDepth
from prompt_toolkit.shortcuts import CompleteStyle, prompt

View file

@ -2,6 +2,7 @@
"""
Example of multiple individual completers that are combined into one.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter, merge_completers
@ -69,7 +70,7 @@ def main():
text = prompt(
"Give some animals: ", completer=completer, complete_while_typing=False
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -3,6 +3,7 @@
Demonstration of a custom completer wrapped in a `FuzzyCompleter` for fuzzy
matching.
"""
from prompt_toolkit.completion import Completer, Completion, FuzzyCompleter
from prompt_toolkit.shortcuts import CompleteStyle, prompt

View file

@ -7,6 +7,7 @@ Press [Tab] to complete the current word.
and shows all the completions. (In the menu)
- Any following tab press cycles through all the possible completions.
"""
from prompt_toolkit.completion import FuzzyWordCompleter
from prompt_toolkit.shortcuts import prompt
@ -52,7 +53,7 @@ def main():
text = prompt(
"Give some animals: ", completer=animal_completer, complete_while_typing=True
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -2,6 +2,7 @@
"""
Autocompletion example that shows meta-information alongside the completions.
"""
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import CompleteStyle, prompt
@ -43,7 +44,7 @@ def main():
completer=animal_completer,
complete_style=CompleteStyle.MULTI_COLUMN,
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -2,6 +2,7 @@
"""
Similar to the autocompletion example. But display all the completions in multiple columns.
"""
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import CompleteStyle, prompt
@ -50,7 +51,7 @@ def main():
completer=animal_completer,
complete_style=CompleteStyle.MULTI_COLUMN,
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -2,6 +2,7 @@
"""
Example of nested autocompletion.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import NestedCompleter
@ -15,7 +16,7 @@ completer = NestedCompleter.from_nested_dict(
def main():
text = prompt("Type a command: ", completer=completer)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -12,6 +12,7 @@ An example of how to deal with slow auto completion code.
- We also set a `loading` boolean in the completer function to keep track of
when the completer is running, and display this in the toolbar.
"""
import time
from prompt_toolkit.completion import Completer, Completion
@ -96,7 +97,7 @@ def main():
bottom_toolbar=bottom_toolbar,
complete_style=CompleteStyle.MULTI_COLUMN,
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -7,6 +7,7 @@ entry of the history starts with the given input, then it will show the
remaining part as a suggestion. Pressing the right arrow will insert this
suggestion.
"""
from prompt_toolkit import PromptSession
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.history import InMemoryHistory
@ -41,7 +42,7 @@ def main():
else:
break
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -4,6 +4,7 @@ Example of implementing auto correction while typing.
The word "impotr" will be corrected when the user types a space afterwards.
"""
from prompt_toolkit import prompt
from prompt_toolkit.key_binding import KeyBindings
@ -37,7 +38,7 @@ def main():
# Read input.
text = prompt("Say something: ", key_bindings=bindings)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -10,6 +10,7 @@ The bottom toolbar will always receive the style 'bottom-toolbar', and the text
inside will get 'bottom-toolbar.text'. These can be used to change the default
style.
"""
import time
from prompt_toolkit import prompt
@ -20,14 +21,14 @@ from prompt_toolkit.styles import Style
def main():
# Example 1: fixed text.
text = prompt("Say something: ", bottom_toolbar="This is a toolbar")
print("You said: %s" % text)
print(f"You said: {text}")
# Example 2: fixed text from a callable:
def get_toolbar():
return "Bottom toolbar: time=%r" % time.time()
return f"Bottom toolbar: time={time.time()!r}"
text = prompt("Say something: ", bottom_toolbar=get_toolbar, refresh_interval=0.5)
print("You said: %s" % text)
print(f"You said: {text}")
# Example 3: Using HTML:
text = prompt(
@ -36,7 +37,7 @@ def main():
'(html) <b>This</b> <u>is</u> a <style bg="ansired">toolbar</style>'
),
)
print("You said: %s" % text)
print(f"You said: {text}")
# Example 4: Using ANSI:
text = prompt(
@ -45,7 +46,7 @@ def main():
"(ansi): \x1b[1mThis\x1b[0m \x1b[4mis\x1b[0m a \x1b[91mtoolbar"
),
)
print("You said: %s" % text)
print(f"You said: {text}")
# Example 5: styling differently.
style = Style.from_dict(
@ -56,7 +57,7 @@ def main():
)
text = prompt("Say something: ", bottom_toolbar="This is a toolbar", style=style)
print("You said: %s" % text)
print(f"You said: {text}")
# Example 6: Using a list of tokens.
def get_bottom_toolbar():
@ -69,11 +70,11 @@ def main():
]
text = prompt("Say something: ", bottom_toolbar=get_bottom_toolbar)
print("You said: %s" % text)
print(f"You said: {text}")
# Example 7: multiline fixed text.
text = prompt("Say something: ", bottom_toolbar="This is\na multiline toolbar")
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -2,6 +2,7 @@
"""
Example of a 'dynamic' prompt. On that shows the current time in the prompt.
"""
import datetime
from prompt_toolkit.shortcuts import prompt
@ -18,7 +19,7 @@ def get_prompt():
def main():
result = prompt(get_prompt, refresh_interval=0.5)
print("You said: %s" % result)
print(f"You said: {result}")
if __name__ == "__main__":

View file

@ -2,6 +2,7 @@
"""
Example of a colored prompt.
"""
from prompt_toolkit import prompt
from prompt_toolkit.formatted_text import ANSI, HTML
from prompt_toolkit.styles import Style
@ -40,7 +41,7 @@ def example_1():
]
answer = prompt(prompt_fragments, style=style)
print("You said: %s" % answer)
print(f"You said: {answer}")
def example_2():
@ -57,7 +58,7 @@ def example_2():
),
style=style,
)
print("You said: %s" % answer)
print(f"You said: {answer}")
def example_3():
@ -72,7 +73,7 @@ def example_3():
"# "
)
)
print("You said: %s" % answer)
print(f"You said: {answer}")
if __name__ == "__main__":

View file

@ -2,8 +2,9 @@
"""
Example of a confirmation prompt.
"""
from prompt_toolkit.shortcuts import confirm
if __name__ == "__main__":
answer = confirm("Should we do that?")
print("You said: %s" % answer)
print(f"You said: {answer}")

View file

@ -2,6 +2,7 @@
"""
Example of cursor shape configurations.
"""
from prompt_toolkit import prompt
from prompt_toolkit.cursor_shapes import CursorShape, ModalCursorShapeConfig

View file

@ -2,6 +2,7 @@
"""
Example of adding a custom key binding to a prompt.
"""
import asyncio
from prompt_toolkit import prompt
@ -70,7 +71,7 @@ def main():
# Read input.
print('Press F4 to insert "hello world", type "xy" to insert "z":')
text = prompt("> ", key_bindings=bindings)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -2,6 +2,7 @@
"""
An example of a custom lexer that prints the input text in random colors.
"""
from prompt_toolkit.lexers import Lexer
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit.styles.named_colors import NAMED_COLORS
@ -22,7 +23,7 @@ class RainbowLexer(Lexer):
def main():
answer = prompt("Give me some input: ", lexer=RainbowLexer())
print("You said: %s" % answer)
print(f"You said: {answer}")
if __name__ == "__main__":

View file

@ -3,6 +3,7 @@
Example of adding a custom Vi operator and text object.
(Note that this API is not guaranteed to remain stable.)
"""
from prompt_toolkit import prompt
from prompt_toolkit.enums import EditingMode
from prompt_toolkit.key_binding import KeyBindings
@ -63,7 +64,7 @@ def main():
text = prompt(
"> ", default="hello world", key_bindings=bindings, editing_mode=EditingMode.VI
)
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -6,6 +6,7 @@ output, even if sys.stdin/stdout are connected to pipes.
For testing, run as:
cat /dev/null | python ./enforce-tty-input-output.py > /dev/null
"""
from prompt_toolkit.application import create_app_session_from_tty
from prompt_toolkit.shortcuts import prompt

View file

@ -9,6 +9,7 @@ See:
- https://github.com/xonsh/xonsh/issues/3356
- https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1111
"""
import datetime
from prompt_toolkit import prompt
@ -72,7 +73,7 @@ def get_prompt() -> HTML:
def main() -> None:
while True:
answer = prompt(get_prompt, style=style, refresh_interval=1)
print("You said: %s" % answer)
print(f"You said: {answer}")
if __name__ == "__main__":

View file

@ -3,6 +3,7 @@
Mark the start and end of the prompt with Final term (iterm2) escape sequences.
See: https://iterm2.com/finalterm.html
"""
import sys
from prompt_toolkit import prompt
@ -39,5 +40,5 @@ if __name__ == "__main__":
# Output.
sys.stdout.write(BEFORE_OUTPUT)
print("You said: %s" % answer)
print(f"You said: {answer}")
sys.stdout.write(AFTER_OUTPUT.format(command_status=0))

View file

@ -4,4 +4,4 @@ from prompt_toolkit import prompt
if __name__ == "__main__":
print("You have Vi keybindings here. Press [Esc] to go to navigation mode.")
answer = prompt("Give me some input: ", multiline=False, vi_mode=True)
print("You said: %s" % answer)
print(f"You said: {answer}")

View file

@ -3,10 +3,11 @@
Example of a call to `prompt` with a default value.
The input is pre-filled, but the user can still edit the default.
"""
import getpass
from prompt_toolkit import prompt
if __name__ == "__main__":
answer = prompt("What is your name: ", default="%s" % getpass.getuser())
print("You said: %s" % answer)
answer = prompt("What is your name: ", default=f"{getpass.getuser()}")
print(f"You said: {answer}")

View file

@ -2,8 +2,9 @@
"""
The most simple prompt example.
"""
from prompt_toolkit import prompt
if __name__ == "__main__":
answer = prompt("Give me some input: ")
print("You said: %s" % answer)
print(f"You said: {answer}")

View file

@ -26,4 +26,4 @@ if __name__ == "__main__":
answer = prompt(
"Multiline input: ", multiline=True, prompt_continuation=prompt_continuation
)
print("You said: %s" % answer)
print(f"You said: {answer}")

View file

@ -3,6 +3,7 @@
get_password function that displays asterisks instead of the actual characters.
With the addition of a ControlT shortcut to hide/show the input.
"""
from prompt_toolkit import prompt
from prompt_toolkit.filters import Condition
from prompt_toolkit.key_binding import KeyBindings
@ -21,7 +22,7 @@ def main():
password = prompt(
"Password: ", is_password=Condition(lambda: hidden[0]), key_bindings=bindings
)
print("You said: %s" % password)
print(f"You said: {password}")
if __name__ == "__main__":

View file

@ -3,4 +3,4 @@ from prompt_toolkit import prompt
if __name__ == "__main__":
password = prompt("Password: ", is_password=True)
print("You said: %s" % password)
print(f"You said: {password}")

View file

@ -4,6 +4,7 @@ Simple example of a CLI that keeps a persistent history of all the entered
strings in a file. When you run this script for a second time, pressing
arrow-up will go back in history.
"""
from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory
@ -18,7 +19,7 @@ def main():
while True:
text = session.prompt("Say something: ")
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -5,6 +5,7 @@ Simple example of a custom, very slow history, that is loaded asynchronously.
By wrapping it in `ThreadedHistory`, the history will load in the background
without blocking any user interaction.
"""
import time
from prompt_toolkit import PromptSession
@ -41,7 +42,7 @@ def main():
while True:
text = session.prompt("Say something: ")
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

View file

@ -3,6 +3,7 @@
Simple example of a syntax-highlighted HTML input line.
(This requires Pygments to be installed.)
"""
from pygments.lexers.html import HtmlLexer
from prompt_toolkit import prompt
@ -11,7 +12,7 @@ from prompt_toolkit.lexers import PygmentsLexer
def main():
text = prompt("Enter HTML: ", lexer=PygmentsLexer(HtmlLexer))
print("You said: %s" % text)
print(f"You said: {text}")
if __name__ == "__main__":

Some files were not shown because too many files have changed in this diff Show more