summaryrefslogtreecommitdiffstats
path: root/examples/prompts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 04:45:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 04:45:14 +0000
commit5b43aaac61ac94abe722bc98ae58468618f2f512 (patch)
tree3d58c89faa23d194f83abb24ae1fd05067538fff /examples/prompts
parentAdding upstream version 3.0.43. (diff)
downloadprompt-toolkit-upstream.tar.xz
prompt-toolkit-upstream.zip
Adding upstream version 3.0.46.upstream/3.0.46upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/prompts')
-rw-r--r--examples/prompts/accept-default.py3
-rwxr-xr-xexamples/prompts/auto-completion/autocomplete-with-control-space.py3
-rwxr-xr-xexamples/prompts/auto-completion/autocompletion-like-readline.py3
-rwxr-xr-xexamples/prompts/auto-completion/autocompletion.py3
-rwxr-xr-xexamples/prompts/auto-completion/colored-completions-with-formatted-text.py1
-rwxr-xr-xexamples/prompts/auto-completion/colored-completions.py1
-rwxr-xr-xexamples/prompts/auto-completion/combine-multiple-completers.py3
-rwxr-xr-xexamples/prompts/auto-completion/fuzzy-custom-completer.py1
-rwxr-xr-xexamples/prompts/auto-completion/fuzzy-word-completer.py3
-rwxr-xr-xexamples/prompts/auto-completion/multi-column-autocompletion-with-meta.py3
-rwxr-xr-xexamples/prompts/auto-completion/multi-column-autocompletion.py3
-rwxr-xr-xexamples/prompts/auto-completion/nested-autocompletion.py3
-rwxr-xr-xexamples/prompts/auto-completion/slow-completions.py3
-rwxr-xr-xexamples/prompts/auto-suggestion.py3
-rwxr-xr-xexamples/prompts/autocorrection.py3
-rwxr-xr-xexamples/prompts/bottom-toolbar.py17
-rwxr-xr-xexamples/prompts/clock-input.py3
-rwxr-xr-xexamples/prompts/colored-prompt.py7
-rwxr-xr-xexamples/prompts/confirmation-prompt.py3
-rwxr-xr-xexamples/prompts/cursor-shapes.py1
-rwxr-xr-xexamples/prompts/custom-key-binding.py3
-rwxr-xr-xexamples/prompts/custom-lexer.py3
-rwxr-xr-xexamples/prompts/custom-vi-operator-and-text-object.py3
-rwxr-xr-xexamples/prompts/enforce-tty-input-output.py1
-rwxr-xr-xexamples/prompts/fancy-zsh-prompt.py3
-rwxr-xr-xexamples/prompts/finalterm-shell-integration.py3
-rwxr-xr-xexamples/prompts/get-input-vi-mode.py2
-rwxr-xr-xexamples/prompts/get-input-with-default.py5
-rwxr-xr-xexamples/prompts/get-input.py3
-rwxr-xr-xexamples/prompts/get-multiline-input.py2
-rwxr-xr-xexamples/prompts/get-password-with-toggle-display-shortcut.py3
-rwxr-xr-xexamples/prompts/get-password.py2
-rwxr-xr-xexamples/prompts/history/persistent-history.py3
-rwxr-xr-xexamples/prompts/history/slow-history.py3
-rwxr-xr-xexamples/prompts/html-input.py3
-rwxr-xr-xexamples/prompts/input-validation.py5
-rwxr-xr-xexamples/prompts/inputhook.py3
-rwxr-xr-xexamples/prompts/mouse-support.py2
-rwxr-xr-xexamples/prompts/multiline-prompt.py3
-rwxr-xr-xexamples/prompts/no-wrapping.py2
-rwxr-xr-xexamples/prompts/operate-and-get-next.py1
-rwxr-xr-xexamples/prompts/patch-stdout.py3
-rwxr-xr-xexamples/prompts/placeholder-text.py3
-rwxr-xr-xexamples/prompts/regular-language.py3
-rwxr-xr-xexamples/prompts/rprompt.py9
-rwxr-xr-xexamples/prompts/swap-light-and-dark-colors.py3
-rwxr-xr-xexamples/prompts/switch-between-vi-emacs.py1
-rwxr-xr-xexamples/prompts/system-clipboard-integration.py3
-rwxr-xr-xexamples/prompts/system-prompt.py6
-rwxr-xr-xexamples/prompts/terminal-title.py2
-rwxr-xr-xexamples/prompts/up-arrow-partial-string-matching.py3
51 files changed, 104 insertions, 60 deletions
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>&lt;rprompt&gt;</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__":