repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
python-prompt-toolkit | examples/full-screen/buttons.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previo... | 93 | 2,390 |
python-prompt-toolkit | examples/full-screen/dummy-app.py | .py | #!/usr/bin/env python
"""
This is the most simple example possible.
"""
from prompt_toolkit import Application
app = Application(full_screen=False)
app.run()
| 10 | 160 |
python-prompt-toolkit | examples/full-screen/ansi-art-and-textarea.py | .py | #!/usr/bin/env python
from prompt_toolkit.application import Application
from prompt_toolkit.formatted_text import ANSI, HTML
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout import HSplit, Layout, VSplit, WindowAlign
from prompt_toolkit.widgets import Dialog, Label, TextArea
def main():... | 83 | 23,815 |
python-prompt-toolkit | examples/full-screen/hello-world.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.widgets import Box, Frame, TextArea
# Layout for displaying hell... | 45 | 937 |
python-prompt-toolkit | examples/full-screen/split-screen.py | .py | #!/usr/bin/env python
"""
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_... | 158 | 5,144 |
python-prompt-toolkit | examples/full-screen/scrollable-panes/simple-example.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_... | 47 | 1,276 |
python-prompt-toolkit | examples/full-screen/scrollable-panes/with-completion-menu.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.... | 122 | 2,826 |
python-prompt-toolkit | examples/full-screen/simple-demos/alignment.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.layout.controls import FormattedTextControl
fr... | 62 | 1,958 |
python-prompt-toolkit | examples/full-screen/simple-demos/horizontal-align.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.layout.containers import (
HorizontalAlign,
HSplit,
VerticalAlign,
VS... | 210 | 7,273 |
python-prompt-toolkit | examples/full-screen/simple-demos/line-prefixes.py | .py | #!/usr/bin/env python
"""
An example of a BufferControl in a full screen layout that offers auto
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 B... | 112 | 3,091 |
python-prompt-toolkit | examples/full-screen/simple-demos/autocompletion.py | .py | #!/usr/bin/env python
"""
An example of a BufferControl in a full screen layout that offers auto
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 B... | 102 | 2,138 |
python-prompt-toolkit | examples/full-screen/simple-demos/floats.py | .py | #!/usr/bin/env python
"""
Floats example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import Float, FloatContainer, Window
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.layout.layou... | 118 | 3,418 |
python-prompt-toolkit | examples/full-screen/simple-demos/horizontal-split.py | .py | #!/usr/bin/env python
"""
Horizontal split example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import HSplit, Window
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.layout.layout imp... | 46 | 948 |
python-prompt-toolkit | examples/full-screen/simple-demos/vertical-align.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.layout.containers import (
HSplit,
VerticalAlign,
VSplit,
Window,
W... | 169 | 5,483 |
python-prompt-toolkit | examples/full-screen/simple-demos/margins.py | .py | #!/usr/bin/env python
"""
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 i... | 73 | 2,183 |
python-prompt-toolkit | examples/full-screen/simple-demos/focus.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.container... | 100 | 2,774 |
python-prompt-toolkit | examples/full-screen/simple-demos/colorcolumn.py | .py | #!/usr/bin/env python
"""
Colorcolumn example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import ColorColumn, HSplit, Window
from prompt_toolkit.layout.controls import BufferCon... | 65 | 1,868 |
python-prompt-toolkit | examples/full-screen/simple-demos/vertical-split.py | .py | #!/usr/bin/env python
"""
Vertical split example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import VSplit, Window
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.layout.layout impor... | 46 | 943 |
python-prompt-toolkit | examples/full-screen/simple-demos/cursorcolumn-cursorline.py | .py | #!/usr/bin/env python
"""
Cursorcolumn / cursorline example.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import HSplit, Window
from prompt_toolkit.layout.controls import BufferCo... | 61 | 1,869 |
python-prompt-toolkit | examples/full-screen/simple-demos/float-transparency.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.layout.containers import Float, FloatContainer... | 89 | 2,742 |
python-prompt-toolkit | examples/tutorial/sqlite-cli.py | .py | #!/usr/bin/env python
import sqlite3
import sys
from pygments.lexers.sql import SqlLexer
from prompt_toolkit import PromptSession
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.lexers import PygmentsLexer
from prompt_toolkit.styles import Style
sql_completer = WordCompleter(
[
"a... | 185 | 3,600 |
python-prompt-toolkit | examples/prompts/html-input.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.lexers import PygmentsLexer
def main():
text = prompt("Enter HTML: ", lexer=PygmentsLex... | 20 | 406 |
python-prompt-toolkit | examples/prompts/custom-lexer.py | .py | #!/usr/bin/env python
"""
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
class RainbowLexer(Lexer):
def lex_document(self, document):
... | 31 | 727 |
python-prompt-toolkit | examples/prompts/get-multiline-input.py | .py | #!/usr/bin/env python
from prompt_toolkit import prompt
from prompt_toolkit.formatted_text import HTML
def prompt_continuation(width, line_number, wrap_count):
"""
The continuation: display line numbers and '->' before soft wraps.
Notice that we can return any kind of formatted text from here.
The p... | 30 | 1,005 |
python-prompt-toolkit | examples/prompts/terminal-title.py | .py | #!/usr/bin/env python
from prompt_toolkit import prompt
from prompt_toolkit.shortcuts import set_title
if __name__ == "__main__":
set_title("This is the terminal title")
answer = prompt("Give me some input: ")
set_title("")
print(f"You said: {answer}")
| 11 | 271 |
python-prompt-toolkit | examples/prompts/get-input-vi-mode.py | .py | #!/usr/bin/env python
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(f"You said: {answer}")
| 8 | 273 |
python-prompt-toolkit | examples/prompts/patch-stdout.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit import prompt
from prompt_toolkit.patch_std... | 43 | 919 |
python-prompt-toolkit | examples/prompts/get-password.py | .py | #!/usr/bin/env python
from prompt_toolkit import prompt
if __name__ == "__main__":
password = prompt("Password: ", is_password=True)
print(f"You said: {password}")
| 7 | 173 |
python-prompt-toolkit | examples/prompts/confirmation-prompt.py | .py | #!/usr/bin/env python
"""
Example of a confirmation prompt.
"""
from prompt_toolkit.shortcuts import confirm
if __name__ == "__main__":
answer = confirm("Should we do that?")
print(f"You said: {answer}")
| 11 | 214 |
python-prompt-toolkit | examples/prompts/enforce-tty-input-output.py | .py | #!/usr/bin/env python
"""
This will display a prompt that will always use the terminal for input and
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... | 15 | 418 |
python-prompt-toolkit | examples/prompts/input-validation.py | .py | #!/usr/bin/env python
"""
Simple example of input validation.
"""
from prompt_toolkit import prompt
from prompt_toolkit.validation import Validator
def is_valid_email(text):
return "@" in text
validator = Validator.from_callable(
is_valid_email,
error_message="Not a valid e-mail address (Does not conta... | 37 | 750 |
python-prompt-toolkit | examples/prompts/fancy-zsh-prompt.py | .py | #!/usr/bin/env python
"""
Example of the fancy ZSH prompt that @anki-code was using.
The theme is coming from the xonsh plugin from the xxh project:
https://github.com/xxh/xxh-plugin-xonsh-theme-bar
See:
- https://github.com/xonsh/xonsh/issues/3356
- https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1111... | 81 | 2,045 |
python-prompt-toolkit | examples/prompts/auto-suggestion.py | .py | #!/usr/bin/env python
"""
Simple example of a CLI that demonstrates fish-style auto suggestion.
When you type some input, it will match the input against the history. If One
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... | 50 | 1,452 |
python-prompt-toolkit | examples/prompts/autocorrection.py | .py | #!/usr/bin/env python
"""
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
# Database of words to be replaced by typing.
corrections = {
"impot... | 46 | 1,095 |
python-prompt-toolkit | examples/prompts/get-input.py | .py | #!/usr/bin/env python
"""
The most simple prompt example.
"""
from prompt_toolkit import prompt
if __name__ == "__main__":
answer = prompt("Give me some input: ")
print(f"You said: {answer}")
| 11 | 202 |
python-prompt-toolkit | examples/prompts/system-prompt.py | .py | #!/usr/bin/env python
from prompt_toolkit import prompt
if __name__ == "__main__":
# System prompt.
print(
"(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(f"You said: {ans... | 21 | 741 |
python-prompt-toolkit | examples/prompts/placeholder-text.py | .py | #!/usr/bin/env python
"""
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
if __name__ == "__main__":
answer = prompt(
"Give me some input: ",
placeholder=HTML('<style color="#888888">(pleas... | 15 | 388 |
python-prompt-toolkit | examples/prompts/regular-language.py | .py | #!/usr/bin/env python
"""
This is an example of "prompt_toolkit.contrib.regular_languages" which
implements a little calculator.
Type for instance::
> add 4 4
> sub 4 4
> sin 3.14
This example shows how you can define the grammar of a regular language and how
to use variables in this grammar with complet... | 110 | 3,155 |
python-prompt-toolkit | examples/prompts/multiline-autosuggest.py | .py | #!/usr/bin/env python
"""
A more complex example of a CLI that demonstrates fish-style auto suggestion
across multiple lines.
This can typically be used for LLM that may return multi-line responses.
Note that unlike simple autosuggest, using multiline autosuggest requires more
care as it may shift the buffer layout, ... | 155 | 5,955 |
python-prompt-toolkit | examples/prompts/inputhook.py | .py | #!/usr/bin/env python
"""
An example that demonstrates how inputhooks can be used in prompt-toolkit.
An inputhook is a callback that an eventloop calls when it's idle. For
instance, readline calls `PyOS_InputHook`. This allows us to do other work in
the same thread, while waiting for input. Important however is that w... | 85 | 2,432 |
python-prompt-toolkit | examples/prompts/colored-prompt.py | .py | #!/usr/bin/env python
"""
Example of a colored prompt.
"""
from prompt_toolkit import prompt
from prompt_toolkit.formatted_text import ANSI, HTML
from prompt_toolkit.styles import Style
style = Style.from_dict(
{
# Default style.
"": "#ff0066",
# Prompt.
"username": "#884444 italic... | 78 | 1,786 |
python-prompt-toolkit | examples/prompts/system-clipboard-integration.py | .py | #!/usr/bin/env python
"""
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
if __name__ == "__main__":
print("Emacs shortcuts:")
print(" Press Control-Y to... | 19 | 609 |
python-prompt-toolkit | examples/prompts/asyncio-prompt.py | .py | #!/usr/bin/env python
"""
This is an example of how to prompt inside an application that uses the asyncio
eventloop. The ``prompt_toolkit`` library will make sure that when other
coroutines are writing to stdout, they write above the prompt, not destroying
the input line.
This example does several things:
1. It sta... | 64 | 1,808 |
python-prompt-toolkit | examples/prompts/get-password-with-toggle-display-shortcut.py | .py | #!/usr/bin/env python
"""
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
def main():
... | 30 | 767 |
python-prompt-toolkit | examples/prompts/rprompt.py | .py | #!/usr/bin/env python
"""
Example of a right prompt. This is an additional prompt that is displayed on
the right side of the terminal. It will be hidden automatically when the input
is long enough to cover the right side of the terminal.
This is similar to RPROMPT is Zsh.
"""
from prompt_toolkit import prompt
from pr... | 55 | 1,517 |
python-prompt-toolkit | examples/prompts/accept-default.py | .py | #!/usr/bin/env python
"""
Example of `accept_default`, a way to automatically accept the input that the
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__":
... | 18 | 466 |
python-prompt-toolkit | examples/prompts/clock-input.py | .py | #!/usr/bin/env python
"""
Example of a 'dynamic' prompt. On that shows the current time in the prompt.
"""
import datetime
from prompt_toolkit.shortcuts import prompt
def get_prompt():
"Tokens to be shown before the prompt."
now = datetime.datetime.now()
return [
("bg:#008800 #ffffff", f"{now.ho... | 27 | 557 |
python-prompt-toolkit | examples/prompts/custom-vi-operator-and-text-object.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.key_binding.bindings.vi im... | 72 | 2,173 |
python-prompt-toolkit | examples/prompts/operate-and-get-next.py | .py | #!/usr/bin/env python
"""
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
def main():
session = PromptSession("prompt>... | 20 | 405 |
python-prompt-toolkit | examples/prompts/multiline-prompt.py | .py | #!/usr/bin/env python
"""
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(f"You said: {answer}")
| 13 | 289 |
python-prompt-toolkit | examples/prompts/mouse-support.py | .py | #!/usr/bin/env python
from prompt_toolkit import prompt
if __name__ == "__main__":
print(
"This is multiline input. press [Meta+Enter] or [Esc] followed by [Enter] to accept input."
)
print("You can click with the mouse in order to select text.")
answer = prompt("Multiline input: ", multiline=T... | 11 | 378 |
python-prompt-toolkit | examples/prompts/bottom-toolbar.py | .py | #!/usr/bin/env python
"""
A few examples of displaying a bottom toolbar.
The ``prompt`` function takes a ``bottom_toolbar`` attribute.
This can be any kind of formatted text (plain text, HTML or ANSI), or
it can be a callable that takes an App and returns an of these.
The bottom toolbar will always receive the style ... | 82 | 2,326 |
python-prompt-toolkit | examples/prompts/up-arrow-partial-string-matching.py | .py | #!/usr/bin/env python
"""
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 InMem... | 43 | 1,216 |
python-prompt-toolkit | examples/prompts/swap-light-and-dark-colors.py | .py | #!/usr/bin/env python
"""
Demonstration of swapping light/dark colors in prompt_toolkit using the
`swap_light_and_dark_colors` parameter.
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... | 80 | 2,015 |
python-prompt-toolkit | examples/prompts/custom-key-binding.py | .py | #!/usr/bin/env python
"""
Example of adding a custom key binding to a prompt.
"""
import asyncio
from prompt_toolkit import prompt
from prompt_toolkit.application import in_terminal, run_in_terminal
from prompt_toolkit.key_binding import KeyBindings
def main():
# We start with a `KeyBindings` of default key bin... | 79 | 2,254 |
python-prompt-toolkit | examples/prompts/cursor-shapes.py | .py | #!/usr/bin/env python
"""
Example of cursor shape configurations.
"""
from prompt_toolkit import prompt
from prompt_toolkit.cursor_shapes import CursorShape, ModalCursorShapeConfig
# NOTE: We pass `enable_suspend=True`, so that we can easily see what happens
# to the cursor shapes when the application is suspen... | 21 | 669 |
python-prompt-toolkit | examples/prompts/switch-between-vi-emacs.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.key_binding import KeyBindings
def run():
# Create a `KeyBi... | 38 | 1,030 |
python-prompt-toolkit | examples/prompts/finalterm-shell-integration.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.formatted_text import ANSI
BEFORE_PROMPT = "\033]133;A\a"
AFTER_PROMPT = "\033]133;B\a"
BEFORE_OUTPUT =... | 45 | 1,309 |
python-prompt-toolkit | examples/prompts/get-input-with-default.py | .py | #!/usr/bin/env python
"""
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=f"{getpass.getuser()}")
print(f"You sa... | 14 | 335 |
python-prompt-toolkit | examples/prompts/no-wrapping.py | .py | #!/usr/bin/env python
from prompt_toolkit import prompt
if __name__ == "__main__":
answer = prompt("Give me some input: ", wrap_lines=False, multiline=True)
print(f"You said: {answer}")
| 7 | 195 |
python-prompt-toolkit | examples/prompts/history/persistent-history.py | .py | #!/usr/bin/env python
"""
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
def main():
ou... | 27 | 728 |
python-prompt-toolkit | examples/prompts/history/slow-history.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.history import Histo... | 50 | 1,367 |
python-prompt-toolkit | examples/prompts/with-frames/gray-frame-on-accept.py | .py | #!/usr/bin/env python
"""
Example of a frame around a prompt input that has autocompletion and a bottom
toolbar.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.styles import Style
animal_completer = WordCompleter(
[
"alligator",
"ant",... | 70 | 1,344 |
python-prompt-toolkit | examples/prompts/with-frames/frame-and-autocompletion.py | .py | #!/usr/bin/env python
"""
Example of a frame around a prompt input that has autocompletion and a bottom
toolbar.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.filters import is_done
animal_completer = WordCompleter(
[
"alligator",
"an... | 64 | 1,269 |
python-prompt-toolkit | examples/prompts/with-frames/with-frame.py | .py | #!/usr/bin/env python
"""
Example of a frame around a prompt input.
"""
from prompt_toolkit import prompt
from prompt_toolkit.styles import Style
style = Style.from_dict(
{
"frame.border": "#884444",
}
)
def example():
"""
Style and list of (style, text) tuples.
"""
answer = prompt("... | 26 | 445 |
python-prompt-toolkit | examples/prompts/auto-completion/nested-autocompletion.py | .py | #!/usr/bin/env python
"""
Example of nested autocompletion.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import NestedCompleter
completer = NestedCompleter.from_nested_dict(
{
"show": {"version": None, "clock": None, "ip": {"interface": {"brief": None}}},
"exit": None,
... | 24 | 468 |
python-prompt-toolkit | examples/prompts/auto-completion/autocomplete-with-control-space.py | .py | #!/usr/bin/env python
"""
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
animal_completer = WordCompleter(
[
"alligator",
"ant",
... | 77 | 1,409 |
python-prompt-toolkit | examples/prompts/auto-completion/colored-completions-with-formatted-text.py | .py | #!/usr/bin/env python
"""
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_tex... | 139 | 3,759 |
python-prompt-toolkit | examples/prompts/auto-completion/colored-completions.py | .py | #!/usr/bin/env python
"""
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
colors = [
... | 80 | 1,938 |
python-prompt-toolkit | examples/prompts/auto-completion/fuzzy-word-completer.py | .py | #!/usr/bin/env python
"""
Autocompletion example.
Press [Tab] to complete the current word.
- The first Tab press fills in the common part of all completions
and shows all the completions. (In the menu)
- Any following tab press cycles through all the possible completions.
"""
from prompt_toolkit.completion impor... | 61 | 1,193 |
python-prompt-toolkit | examples/prompts/auto-completion/autocompletion.py | .py | #!/usr/bin/env python
"""
Autocompletion example.
Press [Tab] to complete the current word.
- The first Tab press fills in the common part of all completions
and shows all the completions. (In the menu)
- Any following tab press cycles through all the possible completions.
"""
from prompt_toolkit import prompt
fr... | 62 | 1,197 |
python-prompt-toolkit | examples/prompts/auto-completion/multi-column-autocompletion.py | .py | #!/usr/bin/env python
"""
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
animal_completer = WordCompleter(
[
"alligator",
"ant",
"... | 59 | 1,092 |
python-prompt-toolkit | examples/prompts/auto-completion/multi-column-autocompletion-with-meta.py | .py | #!/usr/bin/env python
"""
Autocompletion example that shows meta-information alongside the completions.
"""
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import CompleteStyle, prompt
animal_completer = WordCompleter(
[
"alligator",
"ant",
"ape",
... | 52 | 1,211 |
python-prompt-toolkit | examples/prompts/auto-completion/fuzzy-custom-completer.py | .py | #!/usr/bin/env python
"""
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
colors = [
"red",
"blue",
"green",
"orange",
"p... | 58 | 1,369 |
python-prompt-toolkit | examples/prompts/auto-completion/slow-completions.py | .py | #!/usr/bin/env python
"""
An example of how to deal with slow auto completion code.
- Running the completions in a thread is possible by wrapping the
`Completer` object in a `ThreadedCompleter`. This makes sure that the
``get_completions`` generator is executed in a background thread.
For the `prompt` shortcut,... | 105 | 2,649 |
python-prompt-toolkit | examples/prompts/auto-completion/autocompletion-like-readline.py | .py | #!/usr/bin/env python
"""
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
animal_completer = WordCompleter(
[
"alligato... | 60 | 1,121 |
python-prompt-toolkit | examples/prompts/auto-completion/combine-multiple-completers.py | .py | #!/usr/bin/env python
"""
Example of multiple individual completers that are combined into one.
"""
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter, merge_completers
animal_completer = WordCompleter(
[
"alligator",
"ant",
"ape",
"bat",
... | 78 | 1,388 |
python-prompt-toolkit | examples/ssh/asyncssh-server.py | .py | #!/usr/bin/env python
"""
Example of running a prompt_toolkit application in an asyncssh server.
"""
import asyncio
import logging
import asyncssh
from pygments.lexers.html import HtmlLexer
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.contrib.ssh import PromptToolkitSSHServer, PromptToolki... | 122 | 3,195 |
python-prompt-toolkit | examples/print-text/named-colors.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.styles.named_colors import NAMED_COLORS
print = print_formatted_text
def ... | 31 | 884 |
python-prompt-toolkit | examples/print-text/true-color-demo.py | .py | #!/usr/bin/env python
"""
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
print = print_formatted_text
def main():
print(HTML("\n<u>True color test.</u>"))
fo... | 37 | 1,025 |
python-prompt-toolkit | examples/print-text/prompt-toolkit-logo-ansi-art.py | .py | #!/usr/bin/env python
r"""
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
print_forma... | 42 | 22,789 |
python-prompt-toolkit | examples/print-text/print-frame.py | .py | #!/usr/bin/env python
"""
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
print_container(
Frame(
TextArea(text="Hello world!\n"),
title="Stage: pars... | 16 | 332 |
python-prompt-toolkit | examples/print-text/print-formatted-text.py | .py | #!/usr/bin/env python
"""
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
print = print_formatted_text
def main():
style = Style.from_dict(
{
... | 48 | 1,098 |
python-prompt-toolkit | examples/print-text/ansi.py | .py | #!/usr/bin/env python
"""
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 imp... | 52 | 1,225 |
python-prompt-toolkit | examples/print-text/html.py | .py | #!/usr/bin/env python
"""
Demonstration of how to print using the HTML class.
"""
from prompt_toolkit import HTML, print_formatted_text
print = print_formatted_text
def title(text):
print(HTML("\n<u><b>{}</b></u>").format(text))
def main():
title("Special formatting")
print(HTML(" <b>Bold</b>"))
... | 55 | 1,368 |
python-prompt-toolkit | examples/print-text/ansi-colors.py | .py | #!/usr/bin/env python
"""
Demonstration of all the ANSI colors.
"""
from prompt_toolkit import print_formatted_text
from prompt_toolkit.formatted_text import HTML, FormattedText
print = print_formatted_text
def main():
wide_space = ("", " ")
space = ("", " ")
print(HTML("\n<u>Foreground colors</u... | 102 | 3,084 |
python-prompt-toolkit | examples/print-text/pygments-tokens.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit import print_formatted_text
from prompt_toolkit.formatted_text import PygmentsTokens
fro... | 46 | 1,231 |
python-prompt-toolkit | examples/telnet/toolbar.py | .py | #!/usr/bin/env python
"""
Example of a telnet application that displays a bottom toolbar and completions
in the prompt.
"""
import logging
from asyncio import run
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.contrib.telnet.server import TelnetServer
from prompt_toolkit.shortcuts import Prom... | 46 | 1,110 |
python-prompt-toolkit | examples/telnet/dialog.py | .py | #!/usr/bin/env python
"""
Example of a telnet application that displays a dialog window.
"""
import logging
from asyncio import Future, run
from prompt_toolkit.contrib.telnet.server import TelnetServer
from prompt_toolkit.shortcuts.dialogs import yes_no_dialog
# Set up logging
logging.basicConfig()
logging.getLogger... | 36 | 746 |
python-prompt-toolkit | examples/telnet/chat-app.py | .py | #!/usr/bin/env python
"""
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
from prompt_toolkit.contrib.telnet.server import TelnetServer
from prompt_toolkit.formatted_text imp... | 105 | 2,522 |
python-prompt-toolkit | examples/telnet/hello-world.py | .py | #!/usr/bin/env python
"""
A simple Telnet application that asks for input and responds.
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 a... | 41 | 980 |
python-prompt-toolkit | examples/dialogs/input_dialog.py | .py | #!/usr/bin/env python
"""
Example of an input box dialog.
"""
from prompt_toolkit.shortcuts import input_dialog
def main():
result = input_dialog(
title="Input dialog example", text="Please type your name:"
).run()
print(f"Result = {result}")
if __name__ == "__main__":
main()
| 19 | 307 |
python-prompt-toolkit | examples/dialogs/progress_dialog.py | .py | #!/usr/bin/env python
"""
Example of a progress bar dialog.
"""
import os
import time
from prompt_toolkit.shortcuts import progress_dialog
def worker(set_percentage, log_text):
"""
This worker function is called by `progress_dialog`. It will run in a
background thread.
The `set_percentage` function... | 48 | 1,138 |
python-prompt-toolkit | examples/dialogs/checkbox_dialog.py | .py | #!/usr/bin/env python
"""
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
results = checkboxlist_dialog(
title="CheckboxList dialog",
text="What would yo... | 38 | 1,062 |
python-prompt-toolkit | examples/dialogs/styled_messagebox.py | .py | #!/usr/bin/env python
"""
Example of a style dialog window.
All dialog shortcuts take a `style` argument in order to apply a custom
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 messa... | 39 | 932 |
python-prompt-toolkit | examples/dialogs/yes_no_dialog.py | .py | #!/usr/bin/env python
"""
Example of confirmation (yes/no) dialog window.
"""
from prompt_toolkit.shortcuts import yes_no_dialog
def main():
result = yes_no_dialog(
title="Yes/No dialog example", text="Do you want to confirm?"
).run()
print(f"Result = {result}")
if __name__ == "__main__":
... | 19 | 327 |
python-prompt-toolkit | examples/dialogs/password_dialog.py | .py | #!/usr/bin/env python
"""
Example of an password input dialog.
"""
from prompt_toolkit.shortcuts import input_dialog
def main():
result = input_dialog(
title="Password dialog example",
text="Please type your password:",
password=True,
).run()
print(f"Result = {result}")
if __na... | 21 | 351 |
python-prompt-toolkit | examples/dialogs/radio_dialog.py | .py | #!/usr/bin/env python
"""
Example of a radio list box dialog.
"""
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import radiolist_dialog
def main():
result = radiolist_dialog(
values=[
("red", "Red"),
("green", "Green"),
("blue", "Blue"),
... | 41 | 1,065 |
python-prompt-toolkit | examples/dialogs/button_dialog.py | .py | #!/usr/bin/env python
"""
Example of button dialog window.
"""
from prompt_toolkit.shortcuts import button_dialog
def main():
result = button_dialog(
title="Button dialog example",
text="Are you sure?",
buttons=[("Yes", True), ("No", False), ("Maybe...", None)],
).run()
print(f"R... | 21 | 379 |
python-prompt-toolkit | examples/dialogs/messagebox.py | .py | #!/usr/bin/env python
"""
Example of a message box window.
"""
from prompt_toolkit.shortcuts import message_dialog
def main():
message_dialog(
title="Example dialog window",
text="Do you want to continue?\nPress ENTER to quit.",
).run()
if __name__ == "__main__":
main()
| 18 | 304 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.