[Python-modules-commits] [prompt-toolkit] 01/04: Import prompt-toolkit_0.53.orig.tar.gz
Scott Kitterman
kitterman at moszumanska.debian.org
Sun Oct 11 05:24:08 UTC 2015
This is an automated email from the git hooks/post-receive script.
kitterman pushed a commit to branch master
in repository prompt-toolkit.
commit ec734c5b796e5286c971c5f72d4580502814ac85
Author: Scott Kitterman <scott at kitterman.com>
Date: Sun Oct 11 00:58:15 2015 -0400
Import prompt-toolkit_0.53.orig.tar.gz
---
CHANGELOG | 25 ++++++++++
PKG-INFO | 10 ++--
README.rst | 8 ++--
examples/abortaction.retry.py | 14 ++++++
examples/asyncio-prompt.py | 3 --
examples/auto-suggestion.py | 10 ++--
examples/autocompletion.py | 4 +-
examples/autocorrection.py | 4 +-
examples/bottom-toolbar.py | 8 ++--
examples/clock-input.py | 24 ++++------
examples/colored-prompt.py | 4 +-
examples/custom-key-binding.py | 20 ++++++--
examples/get-input-vi-mode.py | 5 +-
examples/get-input-with-default.py | 6 +--
examples/get-input.py | 4 +-
examples/get-multiline-input.py | 4 +-
.../get-password-with-toggle-display-shortcut.py | 8 ++--
examples/get-password.py | 4 +-
examples/html-input.py | 4 +-
examples/input-validation.py | 6 +--
examples/inputhook.py | 10 ++--
examples/mouse-support.py | 4 +-
examples/multi-column-autocompletion-with-meta.py | 4 +-
examples/multi-column-autocompletion.py | 4 +-
examples/multiline-prompt.py | 4 +-
examples/no-wrapping.py | 4 +-
examples/patch-stdout.py | 4 +-
examples/persistent-history.py | 4 +-
examples/regular-language.py | 15 +++---
examples/system-clipboard-integration.py | 4 +-
examples/system-prompt.py | 4 +-
examples/terminal-title.py | 4 +-
examples/tutorial/sqlite-cli.py | 8 ++--
examples/up-arrow-partial-string-matching.py | 8 ++--
prompt_toolkit.egg-info/PKG-INFO | 10 ++--
prompt_toolkit.egg-info/SOURCES.txt | 1 +
prompt_toolkit/__init__.py | 5 +-
prompt_toolkit/auto_suggest.py | 2 +-
prompt_toolkit/buffer.py | 2 +-
prompt_toolkit/clipboard/base.py | 1 -
prompt_toolkit/completion.py | 10 ++++
.../contrib/regular_languages/validation.py | 5 +-
prompt_toolkit/document.py | 8 ++--
prompt_toolkit/interface.py | 20 ++++----
prompt_toolkit/key_binding/bindings/basic.py | 6 +++
prompt_toolkit/key_binding/bindings/vi.py | 7 +++
prompt_toolkit/key_binding/manager.py | 17 ++++++-
prompt_toolkit/keys.py | 1 +
prompt_toolkit/layout/controls.py | 21 +++++++-
prompt_toolkit/layout/menus.py | 7 ++-
prompt_toolkit/layout/toolbars.py | 2 +-
prompt_toolkit/renderer.py | 25 ++++++++--
prompt_toolkit/shortcuts.py | 56 ++++++++++++----------
prompt_toolkit/terminal/vt100_input.py | 1 +
prompt_toolkit/terminal/win32_input.py | 1 +
prompt_toolkit/validation.py | 8 ++--
setup.py | 2 +-
57 files changed, 301 insertions(+), 173 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index ad59b44..63c5a24 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,31 @@
CHANGELOG
=========
+0.53: 2015-10-06
+----------------
+
+New features:
+- Handling of the insert key in Vi mode.
+- Added 'zt' and 'zb' Vi key bindings.
+- Added delete key binding for deleting selected text.
+- Select word below cursor on double mouse click.
+- Added `wrap_lines` option to TokenListControl.
+- Added `KeyBindingManager.for_prompt`.
+
+Fixes:
+- Fix in rendering output.
+- Reset renderer correctly in run_in_terminal.
+- Only reset buffer when using `AbortAction.RETRY`.
+- Fix in handling of exit (Ctrl-D) key presses.
+- Fix in `CompleteEvent`. Correctly set `completion_requested`.
+
+Backwards-incompatible changes:
+- Renamed `ValidationError.index` to `ValidationError.cursor_position`.
+- Renamed `shortcuts.get_input` to `shortcuts.prompt`.
+- Return empty string instead of None in
+ `Document.current_char`/`char_before_cursor`.
+
+
0.52: 2015-09-24
----------------
diff --git a/PKG-INFO b/PKG-INFO
index 76c5cfe..13bf7b9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: prompt_toolkit
-Version: 0.52
+Version: 0.53
Summary: Library for building powerful interactive command lines in Python
Home-page: https://github.com/jonathanslenders/python-prompt-toolkit
Author: Jonathan Slenders
@@ -91,16 +91,16 @@ Description: Python Prompt Toolkit
.. code:: python
- from prompt_toolkit.shortcuts import get_input
+ from prompt_toolkit import prompt
if __name__ == '__main__':
- answer = get_input('Give me some input: ')
+ answer = prompt('Give me some input: ')
print('You said: %s' % answer)
For more complex examples, have a look in the ``examples`` directory. All
examples are chosen to demonstrate only one thing. Also, don't be afraid to
- look at the source code. The implementation of the ``get_input`` function could
- be a good start.
+ look at the source code. The implementation of the ``prompt`` function could be
+ a good start.
Note: For Python 2, you need to add ``from __future__ import unicode_literals``
to the above example. All strings are expected to be unicode strings.
diff --git a/README.rst b/README.rst
index efb6197..45c9eea 100644
--- a/README.rst
+++ b/README.rst
@@ -83,16 +83,16 @@ The most simple example of the library would look like this:
.. code:: python
- from prompt_toolkit.shortcuts import get_input
+ from prompt_toolkit import prompt
if __name__ == '__main__':
- answer = get_input('Give me some input: ')
+ answer = prompt('Give me some input: ')
print('You said: %s' % answer)
For more complex examples, have a look in the ``examples`` directory. All
examples are chosen to demonstrate only one thing. Also, don't be afraid to
-look at the source code. The implementation of the ``get_input`` function could
-be a good start.
+look at the source code. The implementation of the ``prompt`` function could be
+a good start.
Note: For Python 2, you need to add ``from __future__ import unicode_literals``
to the above example. All strings are expected to be unicode strings.
diff --git a/examples/abortaction.retry.py b/examples/abortaction.retry.py
new file mode 100755
index 0000000..0ad3d59
--- /dev/null
+++ b/examples/abortaction.retry.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+"""
+Demontration of the RETRY option.
+
+Pressing Control-C will not throw a `KeyboardInterrupt` like usual, but instead
+the prompt is drawn again.
+"""
+from __future__ import unicode_literals
+from prompt_toolkit import prompt, AbortAction
+
+
+if __name__ == '__main__':
+ answer = prompt('Give me some input: ', on_abort=AbortAction.RETRY)
+ print('You said: %s' % answer)
diff --git a/examples/asyncio-prompt.py b/examples/asyncio-prompt.py
index 1a6085c..7d98660 100755
--- a/examples/asyncio-prompt.py
+++ b/examples/asyncio-prompt.py
@@ -21,9 +21,6 @@ from __future__ import unicode_literals
from prompt_toolkit.interface import CommandLineInterface
from prompt_toolkit.shortcuts import create_default_application, create_asyncio_eventloop
-from pygments.style import Style
-from pygments.token import Token
-
import asyncio
import sys
diff --git a/examples/auto-suggestion.py b/examples/auto-suggestion.py
index cc04ba8..6e26acc 100755
--- a/examples/auto-suggestion.py
+++ b/examples/auto-suggestion.py
@@ -8,7 +8,7 @@ remaining part as a suggestion. Pressing the right arrow will insert this
suggestion.
"""
from __future__ import unicode_literals, print_function
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.interface import AbortAction
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
@@ -29,10 +29,10 @@ def main():
print('Press Control-C to retry. Control-D to exit.')
print()
- text = get_input('Say something: ', history=history,
- auto_suggest=AutoSuggestFromHistory(),
- enable_history_search=True,
- on_abort=AbortAction.RETRY)
+ text = prompt('Say something: ', history=history,
+ auto_suggest=AutoSuggestFromHistory(),
+ enable_history_search=True,
+ on_abort=AbortAction.RETRY)
print('You said: %s' % text)
diff --git a/examples/autocompletion.py b/examples/autocompletion.py
index 529e23a..1b20a90 100755
--- a/examples/autocompletion.py
+++ b/examples/autocompletion.py
@@ -10,7 +10,7 @@ Press [Tab] to complete the current word.
from __future__ import unicode_literals
from prompt_toolkit.contrib.completers import WordCompleter
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
animal_completer = WordCompleter([
@@ -50,7 +50,7 @@ animal_completer = WordCompleter([
def main():
- text = get_input('Give some animals: ', completer=animal_completer)
+ text = prompt('Give some animals: ', completer=animal_completer)
print('You said: %s' % text)
diff --git a/examples/autocorrection.py b/examples/autocorrection.py
index bd43fe9..42b0151 100755
--- a/examples/autocorrection.py
+++ b/examples/autocorrection.py
@@ -6,7 +6,7 @@ The word "impotr" will be corrected when the user types a space afterwards.
"""
from __future__ import unicode_literals
from prompt_toolkit.key_binding.manager import KeyBindingManager
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
# Database of words to be replaced by typing.
corrections = {
@@ -38,7 +38,7 @@ def main():
b.insert_text(' ')
# Read input.
- text = get_input('Say something: ', key_bindings_registry=key_bindings_manager.registry)
+ text = prompt('Say something: ', key_bindings_registry=key_bindings_manager.registry)
print('You said: %s' % text)
diff --git a/examples/bottom-toolbar.py b/examples/bottom-toolbar.py
index 1c39c84..60cd36d 100755
--- a/examples/bottom-toolbar.py
+++ b/examples/bottom-toolbar.py
@@ -3,7 +3,7 @@
Simple example showing a bottom toolbar.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from pygments.token import Token
from pygments.style import Style
@@ -18,9 +18,9 @@ def main():
def get_bottom_toolbar_tokens(cli):
return [(Token.Toolbar, ' This is a toolbar. ')]
- text = get_input('Say something: ',
- get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
- style=TestStyle)
+ text = prompt('Say something: ',
+ get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
+ style=TestStyle)
print('You said: %s' % text)
diff --git a/examples/clock-input.py b/examples/clock-input.py
index cf9d648..85b063a 100755
--- a/examples/clock-input.py
+++ b/examples/clock-input.py
@@ -7,7 +7,7 @@ from prompt_toolkit.interface import CommandLineInterface
from prompt_toolkit.application import Application
from prompt_toolkit.layout import Window
from prompt_toolkit.layout.controls import BufferControl
-from prompt_toolkit.layout.processors import Processor
+from prompt_toolkit.layout.processors import BeforeInput
from prompt_toolkit.layout.utils import token_list_len
from prompt_toolkit.shortcuts import create_eventloop
from prompt_toolkit.utils import Callback
@@ -16,19 +16,13 @@ from pygments.token import Token
import datetime
import time
-
-class ClockPrompt(Processor):
- def run(self, cli, buffer, tokens):
- now = datetime.datetime.now()
- before = [
- (Token.Prompt, '%s:%s:%s' % (now.hour, now.minute, now.second)),
- (Token.Prompt, ' Enter something: ')
- ]
-
- return before + tokens, lambda i: i + token_list_len(before)
-
- def invalidation_hash(self, cli, buffer):
- return datetime.datetime.now()
+def _clock_tokens(cli):
+ " Tokens to be shown before the prompt. "
+ now = datetime.datetime.now()
+ return [
+ (Token.Prompt, '%s:%s:%s' % (now.hour, now.minute, now.second)),
+ (Token.Prompt, ' Enter something: ')
+ ]
def main():
@@ -55,7 +49,7 @@ def main():
done[0] = True
app = Application(
- layout=Window(BufferControl(input_processors=[ClockPrompt()])),
+ layout=Window(BufferControl(input_processors=[BeforeInput(_clock_tokens)])),
on_start=Callback(on_read_start),
on_stop=Callback(on_read_end))
diff --git a/examples/colored-prompt.py b/examples/colored-prompt.py
index dbcb13f..f6ce71d 100755
--- a/examples/colored-prompt.py
+++ b/examples/colored-prompt.py
@@ -4,7 +4,7 @@ Example of a colored prompt.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from pygments.style import Style
from pygments.styles.default import DefaultStyle
from pygments.token import Token
@@ -39,5 +39,5 @@ def get_prompt_tokens(cli):
if __name__ == '__main__':
- answer = get_input(get_prompt_tokens=get_prompt_tokens, style=ExampleStyle)
+ answer = prompt(get_prompt_tokens=get_prompt_tokens, style=ExampleStyle)
print('You said: %s' % answer)
diff --git a/examples/custom-key-binding.py b/examples/custom-key-binding.py
index 6535ff6..80eb902 100755
--- a/examples/custom-key-binding.py
+++ b/examples/custom-key-binding.py
@@ -3,7 +3,7 @@
Example of adding a custom key binding to a prompt.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.key_binding.manager import KeyBindingManager
from prompt_toolkit.keys import Keys
@@ -11,7 +11,7 @@ from prompt_toolkit.keys import Keys
def main():
# We start with a `KeyBindingManager` instance, because this will already
# nicely load all the default key bindings.
- key_bindings_manager = KeyBindingManager()
+ key_bindings_manager = KeyBindingManager.for_prompt()
# Add our own key binding to the registry of the key bindings manager.
@key_bindings_manager.registry.add_binding(Keys.F4)
@@ -33,9 +33,23 @@ def main():
"""
event.cli.current_buffer.insert_text('z')
+ @key_bindings_manager.registry.add_binding(Keys.ControlT)
+ def _(event):
+ """
+ Print 'hello world' in the terminal when ControlT is pressed.
+
+ We use ``run_in_terminal``, because that ensures that the prompt is
+ hidden right before ``print_hello`` gets executed and it's drawn again
+ after it. (Otherwise this would destroy the output.)
+ """
+ def print_hello():
+ print('hello world')
+ event.cli.run_in_terminal(print_hello)
+
+
# Read input.
print('Press F4 to insert "hello world", type "xy" to insert "z":')
- text = get_input('> ', key_bindings_registry=key_bindings_manager.registry)
+ text = prompt('> ', key_bindings_registry=key_bindings_manager.registry)
print('You said: %s' % text)
diff --git a/examples/get-input-vi-mode.py b/examples/get-input-vi-mode.py
index 05c5b12..2794381 100755
--- a/examples/get-input-vi-mode.py
+++ b/examples/get-input-vi-mode.py
@@ -1,10 +1,9 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
-from prompt_toolkit.filters import Always
+from prompt_toolkit import prompt
if __name__ == '__main__':
print("You have Vi keybindings here. Press [Esc] to go to navigation mode.")
- answer = get_input('Give me some input: ', multiline=False, vi_mode=Always())
+ answer = prompt('Give me some input: ', multiline=False, vi_mode=True)
print('You said: %s' % answer)
diff --git a/examples/get-input-with-default.py b/examples/get-input-with-default.py
index a342ec7..34c233b 100755
--- a/examples/get-input-with-default.py
+++ b/examples/get-input-with-default.py
@@ -1,12 +1,12 @@
#!/usr/bin/env python
"""
-Example of a call to `get_input` with a default value.
+Example of a call to `prompt` with a default value.
The input is pre-filled, but the user can still edit the default.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
import getpass
if __name__ == '__main__':
- answer = get_input('What is your name: ', default=getpass.getuser())
+ answer = prompt('What is your name: ', default='%s' % getpass.getuser())
print('You said: %s' % answer)
diff --git a/examples/get-input.py b/examples/get-input.py
index c2ec038..674e692 100755
--- a/examples/get-input.py
+++ b/examples/get-input.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
if __name__ == '__main__':
- answer = get_input('Give me some input: ')
+ answer = prompt('Give me some input: ')
print('You said: %s' % answer)
diff --git a/examples/get-multiline-input.py b/examples/get-multiline-input.py
index e17298b..ef6e3ee 100755
--- a/examples/get-multiline-input.py
+++ b/examples/get-multiline-input.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
if __name__ == '__main__':
print('Press [Meta+Enter] or [Esc] followed by [Enter] to accept input.')
- answer = get_input('Multiline input: ', multiline=True)
+ answer = prompt('Multiline input: ', multiline=True)
print('You said: %s' % answer)
diff --git a/examples/get-password-with-toggle-display-shortcut.py b/examples/get-password-with-toggle-display-shortcut.py
index 0de101f..ae6daf8 100755
--- a/examples/get-password-with-toggle-display-shortcut.py
+++ b/examples/get-password-with-toggle-display-shortcut.py
@@ -4,7 +4,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 __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.key_binding.manager import KeyBindingManager
from prompt_toolkit.keys import Keys
from prompt_toolkit.filters import Condition
@@ -21,9 +21,9 @@ def main():
print('Type Control-T to toggle password visible.')
- password = get_input('Password: ',
- is_password=Condition(lambda cli: hidden[0]),
- key_bindings_registry=key_bindings_manager.registry)
+ password = prompt('Password: ',
+ is_password=Condition(lambda cli: hidden[0]),
+ key_bindings_registry=key_bindings_manager.registry)
print('You said: %s' % password)
diff --git a/examples/get-password.py b/examples/get-password.py
index 9219343..5c2379c 100755
--- a/examples/get-password.py
+++ b/examples/get-password.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
if __name__ == '__main__':
- password = get_input('Password: ', is_password=True)
+ password = prompt('Password: ', is_password=True)
print('You said: %s' % password)
diff --git a/examples/html-input.py b/examples/html-input.py
index d63a52a..678652a 100755
--- a/examples/html-input.py
+++ b/examples/html-input.py
@@ -4,12 +4,12 @@ Simple example of a syntax-highlighted HTML input line.
"""
from __future__ import unicode_literals
from pygments.lexers import HtmlLexer
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.layout.lexers import PygmentsLexer
def main():
- text = get_input('Enter HTML: ', lexer=PygmentsLexer(HtmlLexer))
+ text = prompt('Enter HTML: ', lexer=PygmentsLexer(HtmlLexer))
print('You said: %s' % text)
diff --git a/examples/input-validation.py b/examples/input-validation.py
index 35bcb9a..669d596 100755
--- a/examples/input-validation.py
+++ b/examples/input-validation.py
@@ -5,18 +5,18 @@ Simple example of input validation.
from __future__ import unicode_literals
from prompt_toolkit.validation import Validator, ValidationError
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
class EmailValidator(Validator):
def validate(self, document):
if '@' not in document.text:
raise ValidationError(message='Not a valid e-mail address (Does not contain an @).',
- index=len(document.text)) # Move cursor to end of input.
+ cursor_position=len(document.text)) # Move cursor to end of input.
def main():
- text = get_input('Enter e-mail address: ', validator=EmailValidator())
+ text = prompt('Enter e-mail address: ', validator=EmailValidator())
print('You said: %s' % text)
if __name__ == '__main__':
diff --git a/examples/inputhook.py b/examples/inputhook.py
index 9810c0b..75bb5fc 100755
--- a/examples/inputhook.py
+++ b/examples/inputhook.py
@@ -13,7 +13,7 @@ There are two ways to know when input is ready. One way is to poll
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input, create_eventloop
+from prompt_toolkit.shortcuts import prompt, create_eventloop
from pygments.lexers import PythonLexer
import gtk, gobject
@@ -69,10 +69,10 @@ def main():
# Read input from the command line, using an event loop with this hook.
# We say `patch_stdout=True`, because clicking the button will print
# something; and that should print nicely 'above' the input line.
- result = get_input('Python >>> ',
- eventloop=create_eventloop(inputhook=inputhook),
- lexer=PythonLexer,
- patch_stdout=True)
+ result = prompt('Python >>> ',
+ eventloop=create_eventloop(inputhook=inputhook),
+ lexer=PythonLexer,
+ patch_stdout=True)
print('You said: %s' % result)
diff --git a/examples/mouse-support.py b/examples/mouse-support.py
index acb5595..9661ebe 100755
--- a/examples/mouse-support.py
+++ b/examples/mouse-support.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+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 = get_input('Multiline input: ', multiline=True, mouse_support=True)
+ answer = prompt('Multiline input: ', multiline=True, mouse_support=True)
print('You said: %s' % answer)
diff --git a/examples/multi-column-autocompletion-with-meta.py b/examples/multi-column-autocompletion-with-meta.py
index fd74fd2..adc03bf 100755
--- a/examples/multi-column-autocompletion-with-meta.py
+++ b/examples/multi-column-autocompletion-with-meta.py
@@ -5,7 +5,7 @@ Autocompletion example that shows meta-information alongside the completions.
from __future__ import unicode_literals
from prompt_toolkit.contrib.completers import WordCompleter
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
animal_completer = WordCompleter([
@@ -26,7 +26,7 @@ animal_completer = WordCompleter([
def main():
- text = get_input('Give some animals: ', completer=animal_completer, display_completions_in_columns=True)
+ text = prompt('Give some animals: ', completer=animal_completer, display_completions_in_columns=True)
print('You said: %s' % text)
diff --git a/examples/multi-column-autocompletion.py b/examples/multi-column-autocompletion.py
index 857a0a0..4a11190 100755
--- a/examples/multi-column-autocompletion.py
+++ b/examples/multi-column-autocompletion.py
@@ -5,7 +5,7 @@ Similar to the autocompletion example. But display all the completions in multip
from __future__ import unicode_literals
from prompt_toolkit.contrib.completers import WordCompleter
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
animal_completer = WordCompleter([
@@ -45,7 +45,7 @@ animal_completer = WordCompleter([
def main():
- text = get_input('Give some animals: ', completer=animal_completer, display_completions_in_columns=True)
+ text = prompt('Give some animals: ', completer=animal_completer, display_completions_in_columns=True)
print('You said: %s' % text)
diff --git a/examples/multiline-prompt.py b/examples/multiline-prompt.py
index 4f99d27..c13a690 100755
--- a/examples/multiline-prompt.py
+++ b/examples/multiline-prompt.py
@@ -3,9 +3,9 @@
Demonstration of how the input can be indented.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
if __name__ == '__main__':
- answer = get_input('Give me some input:\n > ', multiline=True)
+ answer = prompt('Give me some input:\n > ', multiline=True)
print('You said: %s' % answer)
diff --git a/examples/no-wrapping.py b/examples/no-wrapping.py
index a29dba1..701212e 100755
--- a/examples/no-wrapping.py
+++ b/examples/no-wrapping.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
if __name__ == '__main__':
- answer = get_input('Give me some input: ', wrap_lines=False, multiline=True)
+ answer = prompt('Give me some input: ', wrap_lines=False, multiline=True)
print('You said: %s' % answer)
diff --git a/examples/patch-stdout.py b/examples/patch-stdout.py
index 357a129..2f952df 100755
--- a/examples/patch-stdout.py
+++ b/examples/patch-stdout.py
@@ -7,7 +7,7 @@ the prompt, but instead is printed nicely above the prompt.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
import threading
import time
@@ -26,7 +26,7 @@ def main():
# Now read the input. The print statements of the other thread
# should not disturb anything.
- result = get_input('Say something: ', patch_stdout=True)
+ result = prompt('Say something: ', patch_stdout=True)
print('You said: %s' % result)
# Stop thrad.
diff --git a/examples/persistent-history.py b/examples/persistent-history.py
index 0a3afea..80ab5d4 100755
--- a/examples/persistent-history.py
+++ b/examples/persistent-history.py
@@ -5,13 +5,13 @@ strings in a file. When you run this script for a second time, pressing
arrow-up will go back in history.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.history import FileHistory
def main():
our_history = FileHistory('.example-history-file')
- text = get_input('Say something: ', history=our_history)
+ text = prompt('Say something: ', history=our_history)
print('You said: %s' % text)
diff --git a/examples/regular-language.py b/examples/regular-language.py
index 1de0998..7edc019 100755
--- a/examples/regular-language.py
+++ b/examples/regular-language.py
@@ -15,10 +15,11 @@ to use variables in this grammar with completers and tokens attached.
from __future__ import unicode_literals
from prompt_toolkit.contrib.completers import WordCompleter
+from prompt_toolkit import prompt
from prompt_toolkit.contrib.regular_languages.compiler import compile
from prompt_toolkit.contrib.regular_languages.completion import GrammarCompleter
from prompt_toolkit.contrib.regular_languages.lexer import GrammarLexer
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit.layout.lexers import SimpleLexer
from prompt_toolkit.styles import DefaultStyle
from pygments.token import Token
@@ -51,11 +52,11 @@ class ExampleStyle(DefaultStyle):
if __name__ == '__main__':
g = create_grammar()
- lexer = GrammarLexer(g, tokens={
- 'operator1': Token.Operator,
- 'operator2': Token.Operator,
- 'var1': Token.Number,
- 'var2': Token.Number
+ lexer = GrammarLexer(g, lexers={
+ 'operator1': SimpleLexer(Token.Operator),
+ 'operator2': SimpleLexer(Token.Operator),
+ 'var1': SimpleLexer(Token.Number),
+ 'var2': SimpleLexer(Token.Number),
})
completer = GrammarCompleter(g, {
@@ -68,7 +69,7 @@ if __name__ == '__main__':
# REPL loop.
while True:
# Read input and parse the result.
- text = get_input('Calculate: ', lexer=lexer, completer=completer, style=ExampleStyle)
+ text = prompt('Calculate: ', lexer=lexer, completer=completer, style=ExampleStyle)
m = g.match(text)
if m:
vars = m.variables()
diff --git a/examples/system-clipboard-integration.py b/examples/system-clipboard-integration.py
index 3823e6e..4ffcdce 100755
--- a/examples/system-clipboard-integration.py
+++ b/examples/system-clipboard-integration.py
@@ -4,7 +4,7 @@ Demonstration of a custom clipboard class.
This requires the 'pyperclip' library to be installed.
"""
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.clipboard.pyperclip import PyperclipClipboard
@@ -15,5 +15,5 @@ if __name__ == '__main__':
print(' Press Control-W to cut to clipboard.')
print('')
- answer = get_input('Give me some input: ', clipboard=PyperclipClipboard())
+ answer = prompt('Give me some input: ', clipboard=PyperclipClipboard())
print('You said: %s' % answer)
diff --git a/examples/system-prompt.py b/examples/system-prompt.py
index 0499f45..a43a709 100755
--- a/examples/system-prompt.py
+++ b/examples/system-prompt.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.filters import Always
if __name__ == '__main__':
print('If you press meta-! or esc-! at the following prompt, you can enter system commands.')
- answer = get_input('Give me some input: ', enable_system_bindings=Always())
+ answer = prompt('Give me some input: ', enable_system_bindings=Always())
print('You said: %s' % answer)
diff --git a/examples/terminal-title.py b/examples/terminal-title.py
index 8ec70cc..0f782a1 100755
--- a/examples/terminal-title.py
+++ b/examples/terminal-title.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
if __name__ == '__main__':
def get_title():
return 'This is the title'
- answer = get_input('Give me some input: ', get_title=get_title)
+ answer = prompt('Give me some input: ', get_title=get_title)
print('You said: %s' % answer)
diff --git a/examples/tutorial/sqlite-cli.py b/examples/tutorial/sqlite-cli.py
index 3ed1339..128e15c 100755
--- a/examples/tutorial/sqlite-cli.py
+++ b/examples/tutorial/sqlite-cli.py
@@ -3,9 +3,8 @@ from __future__ import unicode_literals
import sys
import sqlite3
-from prompt_toolkit import AbortAction
+from prompt_toolkit import AbortAction, prompt
from prompt_toolkit.contrib.completers import WordCompleter
-from prompt_toolkit.shortcuts import get_input
from prompt_toolkit.history import InMemoryHistory
from pygments.lexers import SqlLexer
@@ -31,8 +30,9 @@ def main(database):
while True:
try:
- text = get_input('> ', lexer=SqlLexer, completer=sql_completer, style=DocumentStyle, history=history,
- on_abort=AbortAction.RETRY)
+ text = prompt('> ', lexer=SqlLexer, completer=sql_completer,
+ style=DocumentStyle, history=history,
+ on_abort=AbortAction.RETRY)
except EOFError:
break # Control-D pressed.
diff --git a/examples/up-arrow-partial-string-matching.py b/examples/up-arrow-partial-string-matching.py
index dce649f..c328355 100755
--- a/examples/up-arrow-partial-string-matching.py
+++ b/examples/up-arrow-partial-string-matching.py
@@ -6,7 +6,7 @@ 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 __future__ import unicode_literals, print_function
-from prompt_toolkit.shortcuts import get_input
+from prompt_toolkit import prompt
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.filters import Always
from prompt_toolkit.interface import AbortAction
@@ -27,9 +27,9 @@ def main():
print('Press Control-C to retry. Control-D to exit.')
print()
- text = get_input('Say something: ', history=history,
- enable_history_search=Always(),
- on_abort=AbortAction.RETRY)
+ text = prompt('Say something: ', history=history,
+ enable_history_search=Always(),
+ on_abort=AbortAction.RETRY)
print('You said: %s' % text)
diff --git a/prompt_toolkit.egg-info/PKG-INFO b/prompt_toolkit.egg-info/PKG-INFO
index cdf6f3c..8cb5050 100644
--- a/prompt_toolkit.egg-info/PKG-INFO
+++ b/prompt_toolkit.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: prompt-toolkit
-Version: 0.52
+Version: 0.53
Summary: Library for building powerful interactive command lines in Python
Home-page: https://github.com/jonathanslenders/python-prompt-toolkit
Author: Jonathan Slenders
@@ -91,16 +91,16 @@ Description: Python Prompt Toolkit
.. code:: python
- from prompt_toolkit.shortcuts import get_input
+ from prompt_toolkit import prompt
if __name__ == '__main__':
- answer = get_input('Give me some input: ')
+ answer = prompt('Give me some input: ')
print('You said: %s' % answer)
For more complex examples, have a look in the ``examples`` directory. All
examples are chosen to demonstrate only one thing. Also, don't be afraid to
- look at the source code. The implementation of the ``get_input`` function could
- be a good start.
+ look at the source code. The implementation of the ``prompt`` function could be
+ a good start.
Note: For Python 2, you need to add ``from __future__ import unicode_literals``
to the above example. All strings are expected to be unicode strings.
diff --git a/prompt_toolkit.egg-info/SOURCES.txt b/prompt_toolkit.egg-info/SOURCES.txt
index 00d5084..fcebb25 100644
--- a/prompt_toolkit.egg-info/SOURCES.txt
+++ b/prompt_toolkit.egg-info/SOURCES.txt
@@ -5,6 +5,7 @@ MANIFEST.in
README.rst
TODO.rst
setup.py
+examples/abortaction.retry.py
examples/asyncio-prompt.py
examples/auto-suggestion.py
examples/autocompletion.py
diff --git a/prompt_toolkit/__init__.py b/prompt_toolkit/__init__.py
index 7f28599..5534834 100644
--- a/prompt_toolkit/__init__.py
+++ b/prompt_toolkit/__init__.py
@@ -10,8 +10,9 @@ Description: prompt_toolkit is a Library for building powerful interactive
See the examples directory to learn about the usage.
-Probably, to get started, you meight also want to have a lookt at
-`prompt_toolkit.shortcuts.get_input`.
+Probably, to get started, you meight also want to have a look at
+`prompt_toolkit.shortcuts.prompt`.
"""
from .interface import CommandLineInterface
from .application import AbortAction, Application
+from .shortcuts import prompt
diff --git a/prompt_toolkit/auto_suggest.py b/prompt_toolkit/auto_suggest.py
index 211dece..73ad937 100644
--- a/prompt_toolkit/auto_suggest.py
+++ b/prompt_toolkit/auto_suggest.py
@@ -30,7 +30,7 @@ class Suggestion(object):
self.text = text
def __repr__(self):
- return 'Suggestion(%0)' % self.text
+ return 'Suggestion(%s)' % self.text
class AutoSuggest(with_metaclass(ABCMeta, object)):
diff --git a/prompt_toolkit/buffer.py b/prompt_toolkit/buffer.py
index fa8fea9..9e51e4b 100644
--- a/prompt_toolkit/buffer.py
+++ b/prompt_toolkit/buffer.py
@@ -935,7 +935,7 @@ class Buffer(object):
self.validator.validate(self.document)
except ValidationError as e:
# Set cursor position (don't allow invalid values.)
- cursor_position = e.index
+ cursor_position = e.cursor_position
self.cursor_position = min(max(0, cursor_position), len(self.text))
self.validation_error = e
diff --git a/prompt_toolkit/clipboard/base.py b/prompt_toolkit/clipboard/base.py
index a4b63c8..8dad4d4 100644
--- a/prompt_toolkit/clipboard/base.py
+++ b/prompt_toolkit/clipboard/base.py
@@ -11,7 +11,6 @@ from prompt_toolkit.selection import SelectionType
__all__ = (
'Clipboard',
'ClipboardData',
- 'InMemoryClipboard',
)
diff --git a/prompt_toolkit/completion.py b/prompt_toolkit/completion.py
index 3da9611..9c6b380 100644
--- a/prompt_toolkit/completion.py
+++ b/prompt_toolkit/completion.py
@@ -69,6 +69,16 @@ class Completion(object):
class CompleteEvent(object):
"""
Event that called the completer.
+
+ :param text_inserted: When True, it means that completions are requested
+ because of a text insert. (`Buffer.complete_while_typing`.)
+ :param completion_requested: When True, it means that the user explicitely
+ pressed the `Tab` key in order to view the completions.
+
+ These two flags can be used for instance to implemented a completer that
+ shows some completions when ``Tab`` has been pressed, but not
+ automatically when the user presses a space. (Because of
+ `complete_while_typing`.)
"""
def __init__(self, text_inserted=False, completion_requested=False):
assert not (text_inserted and completion_requested)
diff --git a/prompt_toolkit/contrib/regular_languages/validation.py b/prompt_toolkit/contrib/regular_languages/validation.py
index 7b78831..56db661 100644
--- a/prompt_toolkit/contrib/regular_languages/validation.py
+++ b/prompt_toolkit/contrib/regular_languages/validation.py
@@ -50,7 +50,8 @@ class GrammarValidator(Validator):
validator.validate(inner_document)
... 618 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/prompt-toolkit.git
More information about the Python-modules-commits
mailing list