diff --git a/PROJECTS.rst b/PROJECTS.rst index eabfe13ab..a066e0057 100644 --- a/PROJECTS.rst +++ b/PROJECTS.rst @@ -13,7 +13,7 @@ Shells: - `saws `_: A Supercharged AWS Command Line Interface. - `cycli `_: A Command Line Interface for Cypher. - `crash `_: Crate command line client. -- `vcli `_: Vertica client. +- `vcli `_: Vertical client. - `aws-shell `_: An integrated shell for working with the AWS CLI. - `softlayer-python `_: A command-line interface to manage various SoftLayer products and services. - `ipython `_: The IPython REPL @@ -52,7 +52,7 @@ Full screen applications: - `sanctuary-zero `_: A secure chatroom with zero logging and total transience. - `Hummingbot `_: A Cryptocurrency Algorithmic Trading Platform - `git-bbb `_: A `git blame` browser. -- `ass `_: An OpenAI Assistants API client. Libraries: diff --git a/docs/pages/asking_for_input.rst b/docs/pages/asking_for_input.rst index 20619ac1f..5ad4269d4 100644 --- a/docs/pages/asking_for_input.rst +++ b/docs/pages/asking_for_input.rst @@ -25,7 +25,7 @@ and returns the text. Just like ``(raw_)input``. from prompt_toolkit import prompt text = prompt('Give me some input: ') - print('You said: %s' % text) + print(f'You said: {text}') .. image:: ../images/hello-world-prompt.png @@ -86,7 +86,7 @@ base class. from prompt_toolkit.lexers import PygmentsLexer text = prompt('Enter HTML: ', lexer=PygmentsLexer(HtmlLexer)) - print('You said: %s' % text) + print(f'You said: {text}') .. image:: ../images/html-input.png @@ -105,7 +105,7 @@ you can do the following: style = style_from_pygments_cls(get_style_by_name('monokai')) text = prompt('Enter HTML: ', lexer=PygmentsLexer(HtmlLexer), style=style, include_default_pygments_style=False) - print('You said: %s' % text) + print(f'You said: {text}') We pass ``include_default_pygments_style=False``, because otherwise, both styles will be merged, possibly giving slightly different colors in the outcome @@ -266,7 +266,7 @@ a completer that implements that interface. html_completer = WordCompleter(['', '', '', '']) text = prompt('Enter HTML: ', completer=html_completer) - print('You said: %s' % text) + print(f'You said: {text}') :class:`~prompt_toolkit.completion.WordCompleter` is a simple completer that completes the last word before the cursor with any of the given words. @@ -310,7 +310,7 @@ levels. :class:`~prompt_toolkit.completion.NestedCompleter` solves this issue: }) text = prompt('# ', completer=completer) - print('You said: %s' % text) + print(f'You said: {text}') Whenever there is a ``None`` value in the dictionary, it means that there is no further nested completion at that point. When all values of a dictionary would @@ -476,7 +476,7 @@ takes a :class:`~prompt_toolkit.document.Document` as input and raises cursor_position=i) number = int(prompt('Give a number: ', validator=NumberValidator())) - print('You said: %i' % number) + print(f'You said: {number}') .. image:: ../images/number-validator.png @@ -515,7 +515,7 @@ follows: move_cursor_to_end=True) number = int(prompt('Give a number: ', validator=validator)) - print('You said: %i' % number) + print(f'You said: {number}') We define a function that takes a string, and tells whether it's valid input or not by returning a boolean. @@ -592,7 +592,7 @@ Example: while True: text = session.prompt('> ', auto_suggest=AutoSuggestFromHistory()) - print('You said: %s' % text) + print(f'You said: {text}') .. image:: ../images/auto-suggestion.png @@ -627,7 +627,7 @@ of the foreground. return HTML('This is a <b><style bg="ansired">Toolbar</style></b>!') text = prompt('> ', bottom_toolbar=bottom_toolbar) - print('You said: %s' % text) + print(f'You said: {text}') .. image:: ../images/bottom-toolbar.png @@ -646,7 +646,7 @@ Similar, we could use a list of style/text tuples. }) text = prompt('> ', bottom_toolbar=bottom_toolbar, style=style) - print('You said: %s' % text) + print(f'You said: {text}') The default class name is ``bottom-toolbar`` and that will also be used to fill the background of the toolbar. @@ -734,7 +734,7 @@ An example of a prompt that prints ``'hello world'`` when :kbd:`Control-T` is pr event.app.exit() text = prompt('> ', key_bindings=bindings) - print('You said: %s' % text) + print(f'You said: {text}') Note that we use @@ -892,7 +892,7 @@ A default value can be given: from prompt_toolkit import prompt import getpass - prompt('What is your name: ', default='%s' % getpass.getuser()) + prompt('What is your name: ', default=f"{getpass.getuser()}") Mouse support @@ -990,7 +990,7 @@ returns a coroutines and is awaitable. while True: with patch_stdout(): result = await session.prompt_async('Say something: ') - print('You said: %s' % result) + print(f'You said: {result}') The :func:`~prompt_toolkit.patch_stdout.patch_stdout` context manager is optional, but it's recommended, because other coroutines could print to stdout. diff --git a/docs/pages/getting_started.rst b/docs/pages/getting_started.rst index 06287a080..72d31592e 100644 --- a/docs/pages/getting_started.rst +++ b/docs/pages/getting_started.rst @@ -57,7 +57,7 @@ and returns the text. Just like ``(raw_)input``. from prompt_toolkit import prompt text = prompt('Give me some input: ') - print('You said: %s' % text) + print(f'You said: {text}') Learning `prompt_toolkit` diff --git a/examples/full-screen/simple-demos/line-prefixes.py b/examples/full-screen/simple-demos/line-prefixes.py index 687d43673..15400fd49 100755 --- a/examples/full-screen/simple-demos/line-prefixes.py +++ b/examples/full-screen/simple-demos/line-prefixes.py @@ -33,13 +33,10 @@ def get_line_prefix(lineno, wrap_count): if wrap_count == 0: - return HTML('[%s] <style bg="orange" fg="black">--></style> ') % lineno - + return HTML(f'[{lineno}] <style bg="orange" fg="black">--></style> ') text = str(lineno) + "-" + "*" * (lineno // 2) + ": " - return HTML('[%s.%s] <style bg="ansigreen" fg="ansiblack">%s</style>') % ( - lineno, - wrap_count, - text, + return HTML( + f'[{lineno}.{wrap_count}] <style bg="ansigreen" fg="ansiblack">{text}</style>' ) diff --git a/examples/progress-bar/a-lot-of-parallel-tasks.py b/examples/progress-bar/a-lot-of-parallel-tasks.py index a20982789..007bdb6ff 100755 --- a/examples/progress-bar/a-lot-of-parallel-tasks.py +++ b/examples/progress-bar/a-lot-of-parallel-tasks.py @@ -39,7 +39,7 @@ def stop_task(label, total, sleep_time): threads = [] for i in range(160): - label = "Task %i" % i + label = f"Task {i}" total = random.randrange(50, 200) sleep_time = random.randrange(5, 20) / 100.0 diff --git a/examples/prompts/asyncio-prompt.py b/examples/prompts/asyncio-prompt.py index 32a1481d9..bd97fb3a9 100755 --- a/examples/prompts/asyncio-prompt.py +++ b/examples/prompts/asyncio-prompt.py @@ -26,7 +26,7 @@ async def print_counter(): try: i = 0 while True: - print("Counter: %i" % i) + print(f"Counter: {i}") i += 1 await asyncio.sleep(3) except asyncio.CancelledError: 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 eeff259df..ff75e68e3 100755 --- a/examples/prompts/auto-completion/colored-completions-with-formatted-text.py +++ b/examples/prompts/auto-completion/colored-completions-with-formatted-text.py @@ -97,12 +97,12 @@ def get_completions(self, document, complete_event): family_color = family_colors.get(family, "default") display = HTML( - "%s<b>:</b> <ansired>(<" + f"{animal}<b>:</b> <ansired>(<" + family_color - + ">%s</" + + f">{family}</" + family_color + ">)</ansired>" - ) % (animal, family) + ) else: display = animal diff --git a/examples/prompts/fancy-zsh-prompt.py b/examples/prompts/fancy-zsh-prompt.py index cc31c1f34..51d521924 100755 --- a/examples/prompts/fancy-zsh-prompt.py +++ b/examples/prompts/fancy-zsh-prompt.py @@ -51,9 +51,9 @@ def get_prompt() -> HTML: "<right-part> " "<branch> master<exclamation-mark>!</exclamation-mark> </branch> " " <env> py36 </env> " - " <time>%s</time> " + f" <time>{datetime.datetime.now().isoformat()}</time> " "</right-part>" - ) % (datetime.datetime.now().isoformat(),) + ) used_width = sum( [ @@ -65,7 +65,7 @@ def get_prompt() -> HTML: total_width = get_app().output.get_size().columns padding_size = total_width - used_width - padding = HTML("<padding>%s</padding>") % (" " * padding_size,) + padding = HTML(f"<padding>{" " * padding_size}</padding>") return merge_formatted_text([left_part, padding, right_part, "\n", "# "]) diff --git a/examples/prompts/get-multiline-input.py b/examples/prompts/get-multiline-input.py index cda6fa52c..dd74c633f 100755 --- a/examples/prompts/get-multiline-input.py +++ b/examples/prompts/get-multiline-input.py @@ -17,8 +17,8 @@ def prompt_continuation(width, line_number, wrap_count): if wrap_count > 0: return " " * (width - 3) + "-> " else: - text = ("- %i - " % (line_number + 1)).rjust(width) - return HTML("<strong>%s</strong>") % text + text = (f"- {line_number + 1} - ").rjust(width) + return HTML(f"<strong>{text}</strong>") if __name__ == "__main__": diff --git a/examples/prompts/patch-stdout.py b/examples/prompts/patch-stdout.py index 3a89f3650..7a283b601 100755 --- a/examples/prompts/patch-stdout.py +++ b/examples/prompts/patch-stdout.py @@ -21,7 +21,7 @@ def thread(): i = 0 while running: i += 1 - print("i=%i" % i) + print(f"i={i}") time.sleep(1) t = threading.Thread(target=thread) diff --git a/examples/prompts/swap-light-and-dark-colors.py b/examples/prompts/swap-light-and-dark-colors.py index 4237d7321..9640da7e2 100755 --- a/examples/prompts/swap-light-and-dark-colors.py +++ b/examples/prompts/swap-light-and-dark-colors.py @@ -54,13 +54,10 @@ def bottom_toolbar(): else: on = "on=false" - return ( - HTML( - 'Press <style bg="#222222" fg="#ff8888">[control-t]</style> ' - "to swap between dark/light colors. " - '<style bg="ansiblack" fg="ansiwhite">[%s]</style>' - ) - % on + return HTML( + 'Press <style bg="#222222" fg="#ff8888">[control-t]</style> ' + "to swap between dark/light colors. " + f'<style bg="ansiblack" fg="ansiwhite">[{on}]</style>' ) text = prompt(