diff options
Diffstat (limited to 'examples')
114 files changed, 175 insertions, 75 deletions
diff --git a/examples/dialogs/button_dialog.py b/examples/dialogs/button_dialog.py index 7a99b9a..24e1a47 100755 --- a/examples/dialogs/button_dialog.py +++ b/examples/dialogs/button_dialog.py @@ -2,6 +2,7 @@ """ Example of button dialog window. """ + from prompt_toolkit.shortcuts import button_dialog diff --git a/examples/dialogs/checkbox_dialog.py b/examples/dialogs/checkbox_dialog.py index 90be263..70df166 100755 --- a/examples/dialogs/checkbox_dialog.py +++ b/examples/dialogs/checkbox_dialog.py @@ -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() diff --git a/examples/dialogs/input_dialog.py b/examples/dialogs/input_dialog.py index 6235265..057bc37 100755 --- a/examples/dialogs/input_dialog.py +++ b/examples/dialogs/input_dialog.py @@ -2,6 +2,7 @@ """ Example of an input box dialog. """ + from prompt_toolkit.shortcuts import input_dialog diff --git a/examples/dialogs/messagebox.py b/examples/dialogs/messagebox.py index 4642b84..7b11580 100755 --- a/examples/dialogs/messagebox.py +++ b/examples/dialogs/messagebox.py @@ -2,6 +2,7 @@ """ Example of a message box window. """ + from prompt_toolkit.shortcuts import message_dialog diff --git a/examples/dialogs/password_dialog.py b/examples/dialogs/password_dialog.py index 39d7b9c..d3752ba 100755 --- a/examples/dialogs/password_dialog.py +++ b/examples/dialogs/password_dialog.py @@ -2,6 +2,7 @@ """ Example of an password input dialog. """ + from prompt_toolkit.shortcuts import input_dialog diff --git a/examples/dialogs/progress_dialog.py b/examples/dialogs/progress_dialog.py index 1fd3ffb..7a29f1b 100755 --- a/examples/dialogs/progress_dialog.py +++ b/examples/dialogs/progress_dialog.py @@ -2,6 +2,7 @@ """ Example of a progress bar dialog. """ + import os import time diff --git a/examples/dialogs/radio_dialog.py b/examples/dialogs/radio_dialog.py index 94d80e2..aed9d66 100755 --- a/examples/dialogs/radio_dialog.py +++ b/examples/dialogs/radio_dialog.py @@ -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 diff --git a/examples/dialogs/styled_messagebox.py b/examples/dialogs/styled_messagebox.py index 3f6fc53..5ca197f 100755 --- a/examples/dialogs/styled_messagebox.py +++ b/examples/dialogs/styled_messagebox.py @@ -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 diff --git a/examples/dialogs/yes_no_dialog.py b/examples/dialogs/yes_no_dialog.py index 4b08dd6..6463a38 100755 --- a/examples/dialogs/yes_no_dialog.py +++ b/examples/dialogs/yes_no_dialog.py @@ -2,6 +2,7 @@ """ Example of confirmation (yes/no) dialog window. """ + from prompt_toolkit.shortcuts import yes_no_dialog diff --git a/examples/full-screen/buttons.py b/examples/full-screen/buttons.py index 540194d..f741b26 100755 --- a/examples/full-screen/buttons.py +++ b/examples/full-screen/buttons.py @@ -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 diff --git a/examples/full-screen/calculator.py b/examples/full-screen/calculator.py index 1cb513f..1f2b329 100755 --- a/examples/full-screen/calculator.py +++ b/examples/full-screen/calculator.py @@ -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 diff --git a/examples/full-screen/dummy-app.py b/examples/full-screen/dummy-app.py index 7ea7506..b9e246b 100755 --- a/examples/full-screen/dummy-app.py +++ b/examples/full-screen/dummy-app.py @@ -2,6 +2,7 @@ """ This is the most simple example possible. """ + from prompt_toolkit import Application app = Application(full_screen=False) diff --git a/examples/full-screen/full-screen-demo.py b/examples/full-screen/full-screen-demo.py index de7379a..af3ef5f 100755 --- a/examples/full-screen/full-screen-demo.py +++ b/examples/full-screen/full-screen-demo.py @@ -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__": diff --git a/examples/full-screen/hello-world.py b/examples/full-screen/hello-world.py index b818018..86102d6 100755 --- a/examples/full-screen/hello-world.py +++ b/examples/full-screen/hello-world.py @@ -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 diff --git a/examples/full-screen/no-layout.py b/examples/full-screen/no-layout.py index be5c6f8..a9961c0 100644 --- a/examples/full-screen/no-layout.py +++ b/examples/full-screen/no-layout.py @@ -2,6 +2,7 @@ """ An empty full screen application without layout. """ + from prompt_toolkit import Application Application(full_screen=True).run() diff --git a/examples/full-screen/pager.py b/examples/full-screen/pager.py index 799c834..61336a5 100755 --- a/examples/full-screen/pager.py +++ b/examples/full-screen/pager.py @@ -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"), diff --git a/examples/full-screen/scrollable-panes/simple-example.py b/examples/full-screen/scrollable-panes/simple-example.py index a94274f..cdf2674 100644 --- a/examples/full-screen/scrollable-panes/simple-example.py +++ b/examples/full-screen/scrollable-panes/simple-example.py @@ -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 diff --git a/examples/full-screen/scrollable-panes/with-completion-menu.py b/examples/full-screen/scrollable-panes/with-completion-menu.py index fba8d17..e08609d 100644 --- a/examples/full-screen/scrollable-panes/with-completion-menu.py +++ b/examples/full-screen/scrollable-panes/with-completion-menu.py @@ -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 diff --git a/examples/full-screen/simple-demos/alignment.py b/examples/full-screen/simple-demos/alignment.py index b20b43d..10a8044 100755 --- a/examples/full-screen/simple-demos/alignment.py +++ b/examples/full-screen/simple-demos/alignment.py @@ -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 diff --git a/examples/full-screen/simple-demos/autocompletion.py b/examples/full-screen/simple-demos/autocompletion.py index bcbb594..f041637 100755 --- a/examples/full-screen/simple-demos/autocompletion.py +++ b/examples/full-screen/simple-demos/autocompletion.py @@ -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 diff --git a/examples/full-screen/simple-demos/colorcolumn.py b/examples/full-screen/simple-demos/colorcolumn.py index 054aa44..184b997 100755 --- a/examples/full-screen/simple-demos/colorcolumn.py +++ b/examples/full-screen/simple-demos/colorcolumn.py @@ -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 diff --git a/examples/full-screen/simple-demos/cursorcolumn-cursorline.py b/examples/full-screen/simple-demos/cursorcolumn-cursorline.py index 505b3ee..a6eb5e6 100755 --- a/examples/full-screen/simple-demos/cursorcolumn-cursorline.py +++ b/examples/full-screen/simple-demos/cursorcolumn-cursorline.py @@ -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 diff --git a/examples/full-screen/simple-demos/float-transparency.py b/examples/full-screen/simple-demos/float-transparency.py index 4dc38fc..a7a88c2 100755 --- a/examples/full-screen/simple-demos/float-transparency.py +++ b/examples/full-screen/simple-demos/float-transparency.py @@ -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 diff --git a/examples/full-screen/simple-demos/floats.py b/examples/full-screen/simple-demos/floats.py index 0d45be9..4d79c2b 100755 --- a/examples/full-screen/simple-demos/floats.py +++ b/examples/full-screen/simple-demos/floats.py @@ -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 diff --git a/examples/full-screen/simple-demos/focus.py b/examples/full-screen/simple-demos/focus.py index 9fe9b8f..fbf965e 100755 --- a/examples/full-screen/simple-demos/focus.py +++ b/examples/full-screen/simple-demos/focus.py @@ -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 diff --git a/examples/full-screen/simple-demos/horizontal-align.py b/examples/full-screen/simple-demos/horizontal-align.py index bb0de12..038823a 100755 --- a/examples/full-screen/simple-demos/horizontal-align.py +++ b/examples/full-screen/simple-demos/horizontal-align.py @@ -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 diff --git a/examples/full-screen/simple-demos/horizontal-split.py b/examples/full-screen/simple-demos/horizontal-split.py index 0427e67..660cd57 100755 --- a/examples/full-screen/simple-demos/horizontal-split.py +++ b/examples/full-screen/simple-demos/horizontal-split.py @@ -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 diff --git a/examples/full-screen/simple-demos/line-prefixes.py b/examples/full-screen/simple-demos/line-prefixes.py index b52cb48..687d436 100755 --- a/examples/full-screen/simple-demos/line-prefixes.py +++ b/examples/full-screen/simple-demos/line-prefixes.py @@ -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 diff --git a/examples/full-screen/simple-demos/margins.py b/examples/full-screen/simple-demos/margins.py index 467492d..b60ce0c 100755 --- a/examples/full-screen/simple-demos/margins.py +++ b/examples/full-screen/simple-demos/margins.py @@ -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 diff --git a/examples/full-screen/simple-demos/vertical-align.py b/examples/full-screen/simple-demos/vertical-align.py index 1475d71..13b8504 100755 --- a/examples/full-screen/simple-demos/vertical-align.py +++ b/examples/full-screen/simple-demos/vertical-align.py @@ -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 diff --git a/examples/full-screen/simple-demos/vertical-split.py b/examples/full-screen/simple-demos/vertical-split.py index b48d106..2f4b66f 100755 --- a/examples/full-screen/simple-demos/vertical-split.py +++ b/examples/full-screen/simple-demos/vertical-split.py @@ -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 diff --git a/examples/full-screen/split-screen.py b/examples/full-screen/split-screen.py index af5403e..17e69c9 100755 --- a/examples/full-screen/split-screen.py +++ b/examples/full-screen/split-screen.py @@ -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 diff --git a/examples/full-screen/text-editor.py b/examples/full-screen/text-editor.py index 9c0a414..7fb6b0b 100755 --- a/examples/full-screen/text-editor.py +++ b/examples/full-screen/text-editor.py @@ -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() diff --git a/examples/gevent-get-input.py b/examples/gevent-get-input.py index ecb89b4..0a0f016 100755 --- a/examples/gevent-get-input.py +++ b/examples/gevent-get-input.py @@ -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}") diff --git a/examples/print-text/ansi-colors.py b/examples/print-text/ansi-colors.py index 7bd3831..9e223a5 100755 --- a/examples/print-text/ansi-colors.py +++ b/examples/print-text/ansi-colors.py @@ -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 diff --git a/examples/print-text/ansi.py b/examples/print-text/ansi.py index 618775c..e7a20e4 100755 --- a/examples/print-text/ansi.py +++ b/examples/print-text/ansi.py @@ -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 diff --git a/examples/print-text/html.py b/examples/print-text/html.py index 5276fe3..4edb74d 100755 --- a/examples/print-text/html.py +++ b/examples/print-text/html.py @@ -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 diff --git a/examples/print-text/named-colors.py b/examples/print-text/named-colors.py index ea3f0ba..632b3e4 100755 --- a/examples/print-text/named-colors.py +++ b/examples/print-text/named-colors.py @@ -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 diff --git a/examples/print-text/print-formatted-text.py b/examples/print-text/print-formatted-text.py index 4b09ae2..e2efca9 100755 --- a/examples/print-text/print-formatted-text.py +++ b/examples/print-text/print-formatted-text.py @@ -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 diff --git a/examples/print-text/print-frame.py b/examples/print-text/print-frame.py index fb703c5..8dec82b 100755 --- a/examples/print-text/print-frame.py +++ b/examples/print-text/print-frame.py @@ -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 diff --git a/examples/print-text/prompt-toolkit-logo-ansi-art.py b/examples/print-text/prompt-toolkit-logo-ansi-art.py index 617a506..e34fb03 100755 --- a/examples/print-text/prompt-toolkit-logo-ansi-art.py +++ b/examples/print-text/prompt-toolkit-logo-ansi-art.py @@ -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 diff --git a/examples/print-text/pygments-tokens.py b/examples/print-text/pygments-tokens.py index 3470e8e..a79788a 100755 --- a/examples/print-text/pygments-tokens.py +++ b/examples/print-text/pygments-tokens.py @@ -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 diff --git a/examples/print-text/true-color-demo.py b/examples/print-text/true-color-demo.py index a241006..4debd27 100755 --- a/examples/print-text/true-color-demo.py +++ b/examples/print-text/true-color-demo.py @@ -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 diff --git a/examples/progress-bar/a-lot-of-parallel-tasks.py b/examples/progress-bar/a-lot-of-parallel-tasks.py index 31110ac..a209827 100755 --- a/examples/progress-bar/a-lot-of-parallel-tasks.py +++ b/examples/progress-bar/a-lot-of-parallel-tasks.py @@ -2,6 +2,7 @@ """ More complex demonstration of what's possible with the progress bar. """ + import random import threading import time diff --git a/examples/progress-bar/colored-title-and-label.py b/examples/progress-bar/colored-title-and-label.py index 0b5e73a..bdea5b9 100755 --- a/examples/progress-bar/colored-title-and-label.py +++ b/examples/progress-bar/colored-title-and-label.py @@ -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 diff --git a/examples/progress-bar/custom-key-bindings.py b/examples/progress-bar/custom-key-bindings.py index f700811..f276a1e 100755 --- a/examples/progress-bar/custom-key-bindings.py +++ b/examples/progress-bar/custom-key-bindings.py @@ -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 diff --git a/examples/progress-bar/many-parallel-tasks.py b/examples/progress-bar/many-parallel-tasks.py index dc34ef2..f3af4fe 100755 --- a/examples/progress-bar/many-parallel-tasks.py +++ b/examples/progress-bar/many-parallel-tasks.py @@ -2,6 +2,7 @@ """ More complex demonstration of what's possible with the progress bar. """ + import threading import time diff --git a/examples/progress-bar/nested-progress-bars.py b/examples/progress-bar/nested-progress-bars.py index 1a1e706..cfbf5f2 100755 --- a/examples/progress-bar/nested-progress-bars.py +++ b/examples/progress-bar/nested-progress-bars.py @@ -2,6 +2,7 @@ """ Example of nested progress bars. """ + import time from prompt_toolkit import HTML diff --git a/examples/progress-bar/scrolling-task-name.py b/examples/progress-bar/scrolling-task-name.py index bce155f..5531ace 100755 --- a/examples/progress-bar/scrolling-task-name.py +++ b/examples/progress-bar/scrolling-task-name.py @@ -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 diff --git a/examples/progress-bar/simple-progress-bar.py b/examples/progress-bar/simple-progress-bar.py index c8776e5..672e103 100755 --- a/examples/progress-bar/simple-progress-bar.py +++ b/examples/progress-bar/simple-progress-bar.py @@ -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 diff --git a/examples/progress-bar/styled-1.py b/examples/progress-bar/styled-1.py index d972e55..1f395cf 100755 --- a/examples/progress-bar/styled-1.py +++ b/examples/progress-bar/styled-1.py @@ -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 diff --git a/examples/progress-bar/styled-2.py b/examples/progress-bar/styled-2.py index 15c57d4..f5979b9 100755 --- a/examples/progress-bar/styled-2.py +++ b/examples/progress-bar/styled-2.py @@ -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 diff --git a/examples/progress-bar/styled-apt-get-install.py b/examples/progress-bar/styled-apt-get-install.py index bafe70b..50b6935 100755 --- a/examples/progress-bar/styled-apt-get-install.py +++ b/examples/progress-bar/styled-apt-get-install.py @@ -2,6 +2,7 @@ """ Styled just like an apt-get installation. """ + import time from prompt_toolkit.shortcuts import ProgressBar diff --git a/examples/progress-bar/styled-rainbow.py b/examples/progress-bar/styled-rainbow.py index b46e949..e14e2f0 100755 --- a/examples/progress-bar/styled-rainbow.py +++ b/examples/progress-bar/styled-rainbow.py @@ -2,6 +2,7 @@ """ A simple progress bar, visualized with rainbow colors (for fun). """ + import time from prompt_toolkit.output import ColorDepth diff --git a/examples/progress-bar/styled-tqdm-1.py b/examples/progress-bar/styled-tqdm-1.py index 9484ac0..a24f887 100755 --- a/examples/progress-bar/styled-tqdm-1.py +++ b/examples/progress-bar/styled-tqdm-1.py @@ -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 diff --git a/examples/progress-bar/styled-tqdm-2.py b/examples/progress-bar/styled-tqdm-2.py index 0e66e90..bcdac67 100755 --- a/examples/progress-bar/styled-tqdm-2.py +++ b/examples/progress-bar/styled-tqdm-2.py @@ -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 diff --git a/examples/progress-bar/two-tasks.py b/examples/progress-bar/two-tasks.py index c78604e..36bdf6a 100755 --- a/examples/progress-bar/two-tasks.py +++ b/examples/progress-bar/two-tasks.py @@ -2,6 +2,7 @@ """ Two progress bars that run in parallel. """ + import threading import time diff --git a/examples/progress-bar/unknown-length.py b/examples/progress-bar/unknown-length.py index e39ac39..5d2d06f 100755 --- a/examples/progress-bar/unknown-length.py +++ b/examples/progress-bar/unknown-length.py @@ -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 diff --git a/examples/prompts/accept-default.py b/examples/prompts/accept-default.py index 311ef46..0ef45d9 100644 --- a/examples/prompts/accept-default.py +++ b/examples/prompts/accept-default.py @@ -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}") diff --git a/examples/prompts/auto-completion/autocomplete-with-control-space.py b/examples/prompts/auto-completion/autocomplete-with-control-space.py index 61160a3..238f908 100755 --- a/examples/prompts/auto-completion/autocomplete-with-control-space.py +++ b/examples/prompts/auto-completion/autocomplete-with-control-space.py @@ -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__": diff --git a/examples/prompts/auto-completion/autocompletion-like-readline.py b/examples/prompts/auto-completion/autocompletion-like-readline.py index 613d3e7..eac0edd 100755 --- a/examples/prompts/auto-completion/autocompletion-like-readline.py +++ b/examples/prompts/auto-completion/autocompletion-like-readline.py @@ -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__": diff --git a/examples/prompts/auto-completion/autocompletion.py b/examples/prompts/auto-completion/autocompletion.py index fc9dda0..ea5727f 100755 --- a/examples/prompts/auto-completion/autocompletion.py +++ b/examples/prompts/auto-completion/autocompletion.py @@ -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__": diff --git a/examples/prompts/auto-completion/colored-completions-with-formatted-text.py b/examples/prompts/auto-completion/colored-completions-with-formatted-text.py index 8a89c7a..eeff259 100755 --- a/examples/prompts/auto-completion/colored-completions-with-formatted-text.py +++ b/examples/prompts/auto-completion/colored-completions-with-formatted-text.py @@ -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 diff --git a/examples/prompts/auto-completion/colored-completions.py b/examples/prompts/auto-completion/colored-completions.py index 9c5cba3..1295e7d 100755 --- a/examples/prompts/auto-completion/colored-completions.py +++ b/examples/prompts/auto-completion/colored-completions.py @@ -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 diff --git a/examples/prompts/auto-completion/combine-multiple-completers.py b/examples/prompts/auto-completion/combine-multiple-completers.py index 511988b..7c21078 100755 --- a/examples/prompts/auto-completion/combine-multiple-completers.py +++ b/examples/prompts/auto-completion/combine-multiple-completers.py @@ -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__": diff --git a/examples/prompts/auto-completion/fuzzy-custom-completer.py b/examples/prompts/auto-completion/fuzzy-custom-completer.py index fd9a7d7..ca763c7 100755 --- a/examples/prompts/auto-completion/fuzzy-custom-completer.py +++ b/examples/prompts/auto-completion/fuzzy-custom-completer.py @@ -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 diff --git a/examples/prompts/auto-completion/fuzzy-word-completer.py b/examples/prompts/auto-completion/fuzzy-word-completer.py index 329c0c1..0ea059e 100755 --- a/examples/prompts/auto-completion/fuzzy-word-completer.py +++ b/examples/prompts/auto-completion/fuzzy-word-completer.py @@ -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__": diff --git a/examples/prompts/auto-completion/multi-column-autocompletion-with-meta.py b/examples/prompts/auto-completion/multi-column-autocompletion-with-meta.py index 5ba3ab5..c748837 100755 --- a/examples/prompts/auto-completion/multi-column-autocompletion-with-meta.py +++ b/examples/prompts/auto-completion/multi-column-autocompletion-with-meta.py @@ -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__": diff --git a/examples/prompts/auto-completion/multi-column-autocompletion.py b/examples/prompts/auto-completion/multi-column-autocompletion.py index 7fcfc52..9b24622 100755 --- a/examples/prompts/auto-completion/multi-column-autocompletion.py +++ b/examples/prompts/auto-completion/multi-column-autocompletion.py @@ -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__": diff --git a/examples/prompts/auto-completion/nested-autocompletion.py b/examples/prompts/auto-completion/nested-autocompletion.py index cd85b8c..e56e82e 100755 --- a/examples/prompts/auto-completion/nested-autocompletion.py +++ b/examples/prompts/auto-completion/nested-autocompletion.py @@ -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__": diff --git a/examples/prompts/auto-completion/slow-completions.py b/examples/prompts/auto-completion/slow-completions.py index cce9d59..0c9cc11 100755 --- a/examples/prompts/auto-completion/slow-completions.py +++ b/examples/prompts/auto-completion/slow-completions.py @@ -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__": diff --git a/examples/prompts/auto-suggestion.py b/examples/prompts/auto-suggestion.py index 6660777..56a9dc6 100755 --- a/examples/prompts/auto-suggestion.py +++ b/examples/prompts/auto-suggestion.py @@ -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__": diff --git a/examples/prompts/autocorrection.py b/examples/prompts/autocorrection.py index 6378132..2699554 100755 --- a/examples/prompts/autocorrection.py +++ b/examples/prompts/autocorrection.py @@ -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__": diff --git a/examples/prompts/bottom-toolbar.py b/examples/prompts/bottom-toolbar.py index 4980e5b..937a961 100755 --- a/examples/prompts/bottom-toolbar.py +++ b/examples/prompts/bottom-toolbar.py @@ -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__": diff --git a/examples/prompts/clock-input.py b/examples/prompts/clock-input.py index e43abd8..80bfa51 100755 --- a/examples/prompts/clock-input.py +++ b/examples/prompts/clock-input.py @@ -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__": diff --git a/examples/prompts/colored-prompt.py b/examples/prompts/colored-prompt.py index 1e63e29..428ff1d 100755 --- a/examples/prompts/colored-prompt.py +++ b/examples/prompts/colored-prompt.py @@ -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__": diff --git a/examples/prompts/confirmation-prompt.py b/examples/prompts/confirmation-prompt.py index bd52b9e..18687fe 100755 --- a/examples/prompts/confirmation-prompt.py +++ b/examples/prompts/confirmation-prompt.py @@ -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}") diff --git a/examples/prompts/cursor-shapes.py b/examples/prompts/cursor-shapes.py index e668243..62b2d95 100755 --- a/examples/prompts/cursor-shapes.py +++ b/examples/prompts/cursor-shapes.py @@ -2,6 +2,7 @@ """ Example of cursor shape configurations. """ + from prompt_toolkit import prompt from prompt_toolkit.cursor_shapes import CursorShape, ModalCursorShapeConfig diff --git a/examples/prompts/custom-key-binding.py b/examples/prompts/custom-key-binding.py index 32d889e..b918ab3 100755 --- a/examples/prompts/custom-key-binding.py +++ b/examples/prompts/custom-key-binding.py @@ -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__": diff --git a/examples/prompts/custom-lexer.py b/examples/prompts/custom-lexer.py index c4c9fbe..75ad2d3 100755 --- a/examples/prompts/custom-lexer.py +++ b/examples/prompts/custom-lexer.py @@ -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__": diff --git a/examples/prompts/custom-vi-operator-and-text-object.py b/examples/prompts/custom-vi-operator-and-text-object.py index 7478afc..74bac23 100755 --- a/examples/prompts/custom-vi-operator-and-text-object.py +++ b/examples/prompts/custom-vi-operator-and-text-object.py @@ -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__": diff --git a/examples/prompts/enforce-tty-input-output.py b/examples/prompts/enforce-tty-input-output.py index 93b43ee..08bb762 100755 --- a/examples/prompts/enforce-tty-input-output.py +++ b/examples/prompts/enforce-tty-input-output.py @@ -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 diff --git a/examples/prompts/fancy-zsh-prompt.py b/examples/prompts/fancy-zsh-prompt.py index 4761c08..cc31c1f 100755 --- a/examples/prompts/fancy-zsh-prompt.py +++ b/examples/prompts/fancy-zsh-prompt.py @@ -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__": diff --git a/examples/prompts/finalterm-shell-integration.py b/examples/prompts/finalterm-shell-integration.py index 30c7a7f..254d226 100755 --- a/examples/prompts/finalterm-shell-integration.py +++ b/examples/prompts/finalterm-shell-integration.py @@ -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)) diff --git a/examples/prompts/get-input-vi-mode.py b/examples/prompts/get-input-vi-mode.py index 566ffd5..4073bcd 100755 --- a/examples/prompts/get-input-vi-mode.py +++ b/examples/prompts/get-input-vi-mode.py @@ -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}") diff --git a/examples/prompts/get-input-with-default.py b/examples/prompts/get-input-with-default.py index 67446d5..974888f 100755 --- a/examples/prompts/get-input-with-default.py +++ b/examples/prompts/get-input-with-default.py @@ -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}") diff --git a/examples/prompts/get-input.py b/examples/prompts/get-input.py index 5529bbb..6db7e2c 100755 --- a/examples/prompts/get-input.py +++ b/examples/prompts/get-input.py @@ -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}") diff --git a/examples/prompts/get-multiline-input.py b/examples/prompts/get-multiline-input.py index eda35be..cda6fa5 100755 --- a/examples/prompts/get-multiline-input.py +++ b/examples/prompts/get-multiline-input.py @@ -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}") diff --git a/examples/prompts/get-password-with-toggle-display-shortcut.py b/examples/prompts/get-password-with-toggle-display-shortcut.py index b89cb41..a233e5e 100755 --- a/examples/prompts/get-password-with-toggle-display-shortcut.py +++ b/examples/prompts/get-password-with-toggle-display-shortcut.py @@ -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__": diff --git a/examples/prompts/get-password.py b/examples/prompts/get-password.py index 1c9517c..a9c0c27 100755 --- a/examples/prompts/get-password.py +++ b/examples/prompts/get-password.py @@ -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}") diff --git a/examples/prompts/history/persistent-history.py b/examples/prompts/history/persistent-history.py index 2bdb758..6299bdc 100755 --- a/examples/prompts/history/persistent-history.py +++ b/examples/prompts/history/persistent-history.py @@ -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__": diff --git a/examples/prompts/history/slow-history.py b/examples/prompts/history/slow-history.py index 5b6a7a2..10e4592 100755 --- a/examples/prompts/history/slow-history.py +++ b/examples/prompts/history/slow-history.py @@ -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__": diff --git a/examples/prompts/html-input.py b/examples/prompts/html-input.py index 4c51737..e8ecc00 100755 --- a/examples/prompts/html-input.py +++ b/examples/prompts/html-input.py @@ -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__": diff --git a/examples/prompts/input-validation.py b/examples/prompts/input-validation.py index d8bd3ee..2151671 100755 --- a/examples/prompts/input-validation.py +++ b/examples/prompts/input-validation.py @@ -2,6 +2,7 @@ """ Simple example of input validation. """ + from prompt_toolkit import prompt from prompt_toolkit.validation import Validator @@ -22,13 +23,13 @@ def main(): text = prompt( "Enter e-mail address: ", validator=validator, validate_while_typing=False ) - print("You said: %s" % text) + print(f"You said: {text}") # While typing text = prompt( "Enter e-mail address: ", validator=validator, validate_while_typing=True ) - print("You said: %s" % text) + print(f"You said: {text}") if __name__ == "__main__": diff --git a/examples/prompts/inputhook.py b/examples/prompts/inputhook.py index 7cbfe18..a776246 100755 --- a/examples/prompts/inputhook.py +++ b/examples/prompts/inputhook.py @@ -11,6 +11,7 @@ There are two ways to know when input is ready. One way is to poll `InputHookContext.input_is_ready()`. Another way is to check for `InputHookContext.fileno()` to be ready. In this example we do the latter. """ + import gobject import gtk from pygments.lexers.python import PythonLexer @@ -76,7 +77,7 @@ def main(): "Python >>> ", inputhook=inputhook, lexer=PygmentsLexer(PythonLexer) ) result = session.prompt() - print("You said: %s" % result) + print(f"You said: {result}") if __name__ == "__main__": diff --git a/examples/prompts/mouse-support.py b/examples/prompts/mouse-support.py index 1e4ee76..b1b4bb7 100755 --- a/examples/prompts/mouse-support.py +++ b/examples/prompts/mouse-support.py @@ -7,4 +7,4 @@ if __name__ == "__main__": ) print("You can click with the mouse in order to select text.") answer = prompt("Multiline input: ", multiline=True, mouse_support=True) - print("You said: %s" % answer) + print(f"You said: {answer}") diff --git a/examples/prompts/multiline-prompt.py b/examples/prompts/multiline-prompt.py index d6a7698..f2e70ef 100755 --- a/examples/prompts/multiline-prompt.py +++ b/examples/prompts/multiline-prompt.py @@ -2,10 +2,11 @@ """ Demonstration of how the input can be indented. """ + from prompt_toolkit import prompt if __name__ == "__main__": answer = prompt( "Give me some input: (ESCAPE followed by ENTER to accept)\n > ", multiline=True ) - print("You said: %s" % answer) + print(f"You said: {answer}") diff --git a/examples/prompts/no-wrapping.py b/examples/prompts/no-wrapping.py index 371486e..170e7d5 100755 --- a/examples/prompts/no-wrapping.py +++ b/examples/prompts/no-wrapping.py @@ -3,4 +3,4 @@ from prompt_toolkit import prompt if __name__ == "__main__": answer = prompt("Give me some input: ", wrap_lines=False, multiline=True) - print("You said: %s" % answer) + print(f"You said: {answer}") diff --git a/examples/prompts/operate-and-get-next.py b/examples/prompts/operate-and-get-next.py index 6ea4d79..0bc70ba 100755 --- a/examples/prompts/operate-and-get-next.py +++ b/examples/prompts/operate-and-get-next.py @@ -5,6 +5,7 @@ Demo of "operate-and-get-next". (Actually, this creates one prompt application, and keeps running the same app over and over again. -- For now, this is the only way to get this working.) """ + from prompt_toolkit.shortcuts import PromptSession diff --git a/examples/prompts/patch-stdout.py b/examples/prompts/patch-stdout.py index 1c83524..3a89f36 100755 --- a/examples/prompts/patch-stdout.py +++ b/examples/prompts/patch-stdout.py @@ -5,6 +5,7 @@ An example that demonstrates how `patch_stdout` works. This makes sure that output from other threads doesn't disturb the rendering of the prompt, but instead is printed nicely above the prompt. """ + import threading import time @@ -31,7 +32,7 @@ def main(): # should not disturb anything. with patch_stdout(): result = prompt("Say something: ") - print("You said: %s" % result) + print(f"You said: {result}") # Stop thread. running = False diff --git a/examples/prompts/placeholder-text.py b/examples/prompts/placeholder-text.py index 35e1c6c..65d77a1 100755 --- a/examples/prompts/placeholder-text.py +++ b/examples/prompts/placeholder-text.py @@ -2,6 +2,7 @@ """ Example of a placeholder that's displayed as long as no input is given. """ + from prompt_toolkit import prompt from prompt_toolkit.formatted_text import HTML @@ -10,4 +11,4 @@ if __name__ == "__main__": "Give me some input: ", placeholder=HTML('<style color="#888888">(please type something)</style>'), ) - print("You said: %s" % answer) + print(f"You said: {answer}") diff --git a/examples/prompts/regular-language.py b/examples/prompts/regular-language.py index cbe7256..12cf257 100755 --- a/examples/prompts/regular-language.py +++ b/examples/prompts/regular-language.py @@ -12,6 +12,7 @@ Type for instance:: This example shows how you can define the grammar of a regular language and how to use variables in this grammar with completers and tokens attached. """ + import math from prompt_toolkit import prompt @@ -99,7 +100,7 @@ if __name__ == "__main__": }[vars.get("operator1") or vars.get("operator2")] # Execute and print the result. - print("Result: %s\n" % (operator(var1, var2))) + print(f"Result: {operator(var1, var2)}\n") elif vars.get("operator2"): print("Operator 2") diff --git a/examples/prompts/rprompt.py b/examples/prompts/rprompt.py index f7656b7..fd4fe1b 100755 --- a/examples/prompts/rprompt.py +++ b/examples/prompts/rprompt.py @@ -6,6 +6,7 @@ is long enough to cover the right side of the terminal. This is similar to RPROMPT is Zsh. """ + from prompt_toolkit import prompt from prompt_toolkit.formatted_text import ANSI, HTML from prompt_toolkit.styles import Style @@ -30,23 +31,23 @@ def get_rprompt_text(): def main(): # Option 1: pass a string to 'rprompt': answer = prompt("> ", rprompt=" <rprompt> ", style=example_style) - print("You said: %s" % answer) + print(f"You said: {answer}") # Option 2: pass HTML: answer = prompt("> ", rprompt=HTML(" <u><rprompt></u> "), style=example_style) - print("You said: %s" % answer) + print(f"You said: {answer}") # Option 3: pass ANSI: answer = prompt( "> ", rprompt=ANSI(" \x1b[4m<rprompt>\x1b[0m "), style=example_style ) - print("You said: %s" % answer) + print(f"You said: {answer}") # Option 4: Pass a callable. (This callable can either return plain text, # an HTML object, an ANSI object or a list of (style, text) # tuples. answer = prompt("> ", rprompt=get_rprompt_text, style=example_style) - print("You said: %s" % answer) + print(f"You said: {answer}") if __name__ == "__main__": diff --git a/examples/prompts/swap-light-and-dark-colors.py b/examples/prompts/swap-light-and-dark-colors.py index e602449..4237d73 100755 --- a/examples/prompts/swap-light-and-dark-colors.py +++ b/examples/prompts/swap-light-and-dark-colors.py @@ -7,6 +7,7 @@ Notice that this doesn't swap foreground and background like "reverse" does. It turns light green into dark green and the other way around. Foreground and background are independent of each other. """ + from pygments.lexers.html import HtmlLexer from prompt_toolkit import prompt @@ -71,7 +72,7 @@ def main(): lexer=PygmentsLexer(HtmlLexer), swap_light_and_dark_colors=Condition(lambda: swapped[0]), ) - print("You said: %s" % text) + print(f"You said: {text}") if __name__ == "__main__": diff --git a/examples/prompts/switch-between-vi-emacs.py b/examples/prompts/switch-between-vi-emacs.py index 249c7ef..a69b140 100755 --- a/examples/prompts/switch-between-vi-emacs.py +++ b/examples/prompts/switch-between-vi-emacs.py @@ -3,6 +3,7 @@ Example that displays how to switch between Emacs and Vi input mode. """ + from prompt_toolkit import prompt from prompt_toolkit.application.current import get_app from prompt_toolkit.enums import EditingMode diff --git a/examples/prompts/system-clipboard-integration.py b/examples/prompts/system-clipboard-integration.py index f605921..0b9136b 100755 --- a/examples/prompts/system-clipboard-integration.py +++ b/examples/prompts/system-clipboard-integration.py @@ -3,6 +3,7 @@ Demonstration of a custom clipboard class. This requires the 'pyperclip' library to be installed. """ + from prompt_toolkit import prompt from prompt_toolkit.clipboard.pyperclip import PyperclipClipboard @@ -14,4 +15,4 @@ if __name__ == "__main__": print("") answer = prompt("Give me some input: ", clipboard=PyperclipClipboard()) - print("You said: %s" % answer) + print(f"You said: {answer}") diff --git a/examples/prompts/system-prompt.py b/examples/prompts/system-prompt.py index 47aa2a5..e9ff460 100755 --- a/examples/prompts/system-prompt.py +++ b/examples/prompts/system-prompt.py @@ -7,14 +7,14 @@ if __name__ == "__main__": "(1/3) If you press meta-! or esc-! at the following prompt, you can enter system commands." ) answer = prompt("Give me some input: ", enable_system_prompt=True) - print("You said: %s" % answer) + print(f"You said: {answer}") # Enable suspend. print("(2/3) If you press Control-Z, the application will suspend.") answer = prompt("Give me some input: ", enable_suspend=True) - print("You said: %s" % answer) + print(f"You said: {answer}") # Enable open_in_editor print("(3/3) If you press Control-X Control-E, the prompt will open in $EDITOR.") answer = prompt("Give me some input: ", enable_open_in_editor=True) - print("You said: %s" % answer) + print(f"You said: {answer}") diff --git a/examples/prompts/terminal-title.py b/examples/prompts/terminal-title.py index 14f9459..dc49c26 100755 --- a/examples/prompts/terminal-title.py +++ b/examples/prompts/terminal-title.py @@ -7,4 +7,4 @@ if __name__ == "__main__": answer = prompt("Give me some input: ") set_title("") - print("You said: %s" % answer) + print(f"You said: {answer}") diff --git a/examples/prompts/up-arrow-partial-string-matching.py b/examples/prompts/up-arrow-partial-string-matching.py index 742a12e..999b1f9 100755 --- a/examples/prompts/up-arrow-partial-string-matching.py +++ b/examples/prompts/up-arrow-partial-string-matching.py @@ -5,6 +5,7 @@ Simple example of a CLI that demonstrates up-arrow partial string matching. When you type some input, it's possible to use the up arrow to filter the history on the items starting with the given input text. """ + from prompt_toolkit import PromptSession from prompt_toolkit.history import InMemoryHistory @@ -34,7 +35,7 @@ def main(): else: break - print("You said: %s" % text) + print(f"You said: {text}") if __name__ == "__main__": diff --git a/examples/ssh/asyncssh-server.py b/examples/ssh/asyncssh-server.py index 27d0dd2..0b09f2b 100755 --- a/examples/ssh/asyncssh-server.py +++ b/examples/ssh/asyncssh-server.py @@ -2,6 +2,7 @@ """ Example of running a prompt_toolkit application in an asyncssh server. """ + import asyncio import logging diff --git a/examples/telnet/chat-app.py b/examples/telnet/chat-app.py index 2e3508d..8f4cb2c 100755 --- a/examples/telnet/chat-app.py +++ b/examples/telnet/chat-app.py @@ -4,6 +4,7 @@ A simple chat application over telnet. Everyone that connects is asked for his name, and then people can chat with each other. """ + import logging import random from asyncio import Future, run @@ -84,9 +85,9 @@ def _send_to_everyone(sender_connection, name, message, color): if c != sender_connection: c.send_above_prompt( [ - ("fg:" + color, "[%s]" % name), + ("fg:" + color, f"[{name}]"), ("", " "), - ("fg:" + color, "%s\n" % message), + ("fg:" + color, f"{message}\n"), ] ) diff --git a/examples/telnet/dialog.py b/examples/telnet/dialog.py index c674a9d..1044fb0 100755 --- a/examples/telnet/dialog.py +++ b/examples/telnet/dialog.py @@ -2,6 +2,7 @@ """ Example of a telnet application that displays a dialog window. """ + import logging from asyncio import Future, run diff --git a/examples/telnet/hello-world.py b/examples/telnet/hello-world.py index c19c60c..f7bbda1 100755 --- a/examples/telnet/hello-world.py +++ b/examples/telnet/hello-world.py @@ -6,6 +6,7 @@ The interaction function is a prompt_toolkit coroutine. Also see the `hello-world-asyncio.py` example which uses an asyncio coroutine. That is probably the preferred way if you only need Python 3 support. """ + import logging from asyncio import run diff --git a/examples/telnet/toolbar.py b/examples/telnet/toolbar.py index d6ae886..6e31c9f 100755 --- a/examples/telnet/toolbar.py +++ b/examples/telnet/toolbar.py @@ -3,6 +3,7 @@ Example of a telnet application that displays a bottom toolbar and completions in the prompt. """ + import logging from asyncio import run |