[Python-modules-commits] [prompt-toolkit] 01/04: Import prompt-toolkit_0.60.orig.tar.gz

Scott Kitterman kitterman at moszumanska.debian.org
Sun Apr 3 02:02:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

kitterman pushed a commit to branch master
in repository prompt-toolkit.

commit a26a5f52fdcc079b0be8bd853cd73d3e1972c403
Author: Scott Kitterman <scott at kitterman.com>
Date:   Sat Apr 2 21:59:05 2016 -0400

    Import prompt-toolkit_0.60.orig.tar.gz
---
 CHANGELOG                                         | 102 +++
 PKG-INFO                                          |  32 +-
 README.rst                                        |  13 +-
 examples/autocompletion.py                        |   7 +-
 examples/bottom-toolbar.py                        |   6 +-
 examples/clock-input.py                           |   4 +-
 examples/colored-prompt.py                        |  10 +-
 examples/full-screen-layout.py                    |   7 +-
 examples/get-multiline-input.py                   |  12 +-
 examples/html-input.py                            |   1 +
 examples/print-tokens.py                          |  25 +
 examples/regular-language.py                      |   7 +-
 examples/rprompt.py                               |  29 +
 examples/switch-between-vi-emacs.py               |  20 +-
 prompt_toolkit.egg-info/PKG-INFO                  |  32 +-
 prompt_toolkit.egg-info/SOURCES.txt               |  14 +-
 prompt_toolkit.egg-info/requires.txt              |   1 -
 prompt_toolkit/__init__.py                        |   3 +-
 prompt_toolkit/application.py                     |   5 +-
 prompt_toolkit/buffer.py                          |  54 +-
 prompt_toolkit/cache.py                           |  86 +++
 prompt_toolkit/contrib/regular_languages/lexer.py |  28 +-
 prompt_toolkit/document.py                        | 268 ++++++--
 prompt_toolkit/eventloop/asyncio_win32.py         |   2 +
 prompt_toolkit/eventloop/win32.py                 |  21 +-
 prompt_toolkit/filters/base.py                    |  33 +-
 prompt_toolkit/filters/types.py                   |  56 +-
 prompt_toolkit/filters/utils.py                   |   8 +-
 prompt_toolkit/history.py                         |   3 +-
 prompt_toolkit/interface.py                       | 101 ++-
 prompt_toolkit/key_binding/bindings/basic.py      |  13 +-
 prompt_toolkit/key_binding/bindings/emacs.py      |  39 +-
 prompt_toolkit/key_binding/bindings/scroll.py     |  93 +--
 prompt_toolkit/key_binding/bindings/vi.py         |  74 ++-
 prompt_toolkit/key_binding/manager.py             |   2 +-
 prompt_toolkit/key_binding/registry.py            |   1 +
 prompt_toolkit/keys.py                            |   8 +
 prompt_toolkit/layout/__init__.py                 |   2 +-
 prompt_toolkit/layout/containers.py               | 741 ++++++++++++++++------
 prompt_toolkit/layout/controls.py                 | 658 +++++++++----------
 prompt_toolkit/layout/highlighters.py             | 209 ------
 prompt_toolkit/layout/lexers.py                   | 261 +++++++-
 prompt_toolkit/layout/margins.py                  | 195 ++++--
 prompt_toolkit/layout/menus.py                    | 141 ++--
 prompt_toolkit/layout/processors.py               | 446 +++++++------
 prompt_toolkit/layout/prompt.py                   |  20 +-
 prompt_toolkit/layout/screen.py                   | 115 +---
 prompt_toolkit/layout/toolbars.py                 |  21 +-
 prompt_toolkit/layout/utils.py                    |  45 +-
 prompt_toolkit/output.py                          |   4 +
 prompt_toolkit/renderer.py                        |  14 +-
 prompt_toolkit/shortcuts.py                       | 191 ++++--
 prompt_toolkit/styles.py                          | 221 -------
 prompt_toolkit/styles/__init__.py                 |  20 +
 prompt_toolkit/styles/base.py                     |  86 +++
 prompt_toolkit/styles/defaults.py                 |  83 +++
 prompt_toolkit/styles/from_dict.py                | 143 +++++
 prompt_toolkit/styles/from_pygments.py            |  71 +++
 prompt_toolkit/terminal/conemu_output.py          |   3 +-
 prompt_toolkit/terminal/vt100_input.py            |  25 +
 prompt_toolkit/terminal/vt100_output.py           | 317 ++++++---
 prompt_toolkit/terminal/win32_input.py            |  19 +-
 prompt_toolkit/terminal/win32_output.py           |  91 ++-
 prompt_toolkit/token.py                           |  38 ++
 prompt_toolkit/utils.py                           |  39 +-
 prompt_toolkit/validation.py                      |   2 +-
 setup.cfg                                         |   2 +-
 setup.py                                          |  32 +-
 tests/filter_tests.py                             | 153 +++++
 tests/layout_tests/__init__.py                    |   2 +-
 tests/run_tests.py                                |   7 +-
 tests/screen_tests/__init__.py                    |  96 ---
 tests/style_tests.py                              |  41 ++
 73 files changed, 3684 insertions(+), 2090 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index de2d7f6..ac06351 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,108 @@ About the version numbering:
     to a <breaking>.<feature>.<fix> style of numbering.
 
 
+0.60: 2016-03-14
+----------------
+
+Fixes:
+- Fix in Document.paste. (The screen was not updated after an undo of a paste.)
+- Don't use deprecated inspect.getargspec on Python 3.
+- Fixed reading input on Windows when input was piped in stdin.
+- Use correct file descriptors for input/output in run_system_command.
+- Always correctly split prompt in shortcuts.prompt. (Even when multiline=False)
+- Correctly align right prompt to the top when the left prompt consists of
+  multiple lines.
+- Correctly use Token.Transparent as default token for a TokenListControl.
+- Fix in syntax synchronisation. (Better handle the case when no
+  synchronisation point was found.)
+- Send SIGTSTP to the whole process group.
+- Correctly raise on_buffer_changed on all text changes.
+- Fix in regular_languages.GrammarLexer. (Fixes bug in ptipython syntax
+  highlighting.)
+
+New features:
+- Add support for additional readers to the Win32 event loop.
+- Added on_render event.
+- Carry the weight in layout dimensions to allow stretching.
+
+
+0.59: 2016-02-27
+----------------
+
+Fixes:
+- Set correct default color on Windows. (Gray instead of high intensity gray.)
+- Reverse colors on Windows when foreground/background color have not been
+  specified.
+- Correct handling of mouse events for FillControl.
+- Take margin into account when calculating Window height. (Fixes bug in
+  multiline prompt.)
+- Handle division by zero in UIContent.get_height_for_text.
+
+
+0.58: 2016-02-23
+----------------
+
+Fixes:
+- Correctly return result for mouse handler in TokenListControl.
+- Bugfix in meta-backspace key binding. (Delete all whitespace before the
+  cursor, when there is only whitespace.)
+- Bugfix in Vi gu, gU, g? and g~ key bindings (in selection mode).
+- Correctly restore default console attributes on Windows.
+- Disable bracketed paste support in ConEmu. (This was broken.)
+- When an unknown exception is raised in `CommandLineInterface.run()`, don't
+  forget to redraw the CLI.
+
+New features:
+- Many performance improvements and better caching. (Especially in the
+  `Document` class.)
+- Support for continuation tokens in `shortcuts.prompt` and
+  `shortcuts.create_prompt_layout`.
+- Added `shortcuts.print_tokens` function for printing colored output.
+- Sound bell when nothing was deleted.
+- Added escape sequences for F1-F5 keys on the Linux console.
+- Improved support for the Linux console. (Switch back to 16 colors.)
+- Added F13-F24 input codes for xterm.
+- Created prompt_toolkit.token. A custom Token implementation, that is
+  compatible with Pygments.token. (This way, Pygments becomes an optional
+  dependency. For many use cases, nothing except the Token class from Pygments
+  was used, so it was a bit overkill to install Pygments for only that.)
+- Refactoring of prompt_toolkit.styles.
+- `Float` objects got a `hide_when_covering_content` option.
+- Implementation of RPROMPT, like ZSH: Added `get_rprompt_tokens` to
+  `create_prompt_layout`.
+- Some improvements to the default style.
+- Also handle Ctrl-R and Ctrl-S in Vi mode when searching.
+- Added TabsProcessor: a tool to visualise tabs instead of displaying ^I.
+- Give a better error message when trying to run in git-bash.
+- Support for ANSI color names in style dictionaries.
+
+- Big refactoring of the `Window` and `UIControl` classes. This should result
+  in huge performance improvements on big inputs. (While first, a document
+  could have 1,000 lines; now it can have about 100,000 lines on the same system.)
+
+  The Window and UIControl have been rewritten very much. Rather than each time
+  rendering the whole user control, we now only have to render the visible part.
+
+  Because of this, many pieces had to be rewritten:
+  - UIControls work differently. They return a `UIContent` instance that
+    consist of a collection of lines.
+  - All processors have been rewritten. (Their API changed as well, because
+    they process one line at a time.)
+  - Lexers work differently. `Lexer.lex_document` should now return a function
+    that returns the tokens for one line. PygmentsLexer has been optimized that
+    it becomes 'lazy', and it has optional syntax synchronisation. That means,
+    that the lexer doesn't have to start the lexing at the beginning of the
+    document. (Which would be slow for big documents.)
+
+Backwards-incompatible changes:
+- As mentioned above, the refactoring of `Window` and `UIControl` caused many
+  "internal" APIs to change. All custom `UIControl`, `Processor` and `Lexer`
+  classes have to be rewritten. However, for most applications this should not
+  be an issue. Especially, the `shortcuts.prompt` function is
+  backwards-compatible.
+- `wrap_lines` became a property of `Window` instead of `BufferControl`.
+
+
 0.57: 2016-01-04
 ----------------
 
diff --git a/PKG-INFO b/PKG-INFO
index bb1c0c3..128f1a9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,11 +1,11 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
 Name: prompt_toolkit
-Version: 0.57
+Version: 0.60
 Summary: Library for building powerful interactive command lines in Python
 Home-page: https://github.com/jonathanslenders/python-prompt-toolkit
 Author: Jonathan Slenders
 Author-email: UNKNOWN
-License: LICENSE.txt
+License: UNKNOWN
 Description: Python Prompt Toolkit
         =====================
         
@@ -15,7 +15,7 @@ Description: Python Prompt Toolkit
         and terminal applications in Python.
         
         Read the `documentation on readthedocs
-        <http://python-prompt-toolkit.readthedocs.org/en/latest/>`_.
+        <http://python-prompt-toolkit.readthedocs.org/en/stable/>`_.
         
         
         Ptpython
@@ -51,8 +51,8 @@ Description: Python Prompt Toolkit
         - Multiple input buffers.
         - No global state.
         - Lightweight, the only dependencies are Pygments, six and wcwidth.
-        - Code written with love.
         - Runs on Linux, OS X, OpenBSD and Windows systems.
+        - And much more...
         
         Feel free to create tickets for bugs and feature requests, and create pull
         requests if you have nice patches that you would like to share with others.
@@ -72,7 +72,7 @@ Description: Python Prompt Toolkit
         general, the Unix experience will still be a little better.
         
         For Windows, it's recommended to use either `cmder
-        <http://gooseberrycreative.com/cmder/>`_ or `conemu <https://conemu.github.io/>`_.
+        <http://cmder.net/>`_ or `conemu <https://conemu.github.io/>`_.
         
         
         Installation
@@ -107,8 +107,9 @@ Description: Python Prompt Toolkit
         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.
+        Note for Python 2: all strings are expected to be unicode strings. So, either
+        put a small ``u`` in front of every string or put ``from __future__ import
+        unicode_literals`` at the start of the above example.
         
         
         Projects using prompt-toolkit
@@ -127,6 +128,8 @@ Description: Python Prompt Toolkit
         - `crash <https://github.com/crate/crash>`_:  Crate command line client.
         - `vcli <https://github.com/dbcli/vcli>`_: Vertica client.
         - `aws-shell <https://github.com/awslabs/aws-shell>`_: An integrated shell for working with the AWS CLI.
+        - `softlayer-python <https://github.com/softlayer/softlayer-python>`_: A command-line interface to manage various SoftLayer products and services.
+        - `ipython <http://github.com/ipython/ipython/>`_: The IPython REPL
         
         Full screen applications:
         
@@ -168,3 +171,16 @@ Description: Python Prompt Toolkit
             :alt: Latest Version
         
 Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: BSD License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python
+Classifier: Topic :: Software Development
diff --git a/README.rst b/README.rst
index 3a7e95e..ce28b6a 100644
--- a/README.rst
+++ b/README.rst
@@ -7,7 +7,7 @@ Python Prompt Toolkit
 and terminal applications in Python.
 
 Read the `documentation on readthedocs
-<http://python-prompt-toolkit.readthedocs.org/en/latest/>`_.
+<http://python-prompt-toolkit.readthedocs.org/en/stable/>`_.
 
 
 Ptpython
@@ -43,8 +43,8 @@ Some features:
 - Multiple input buffers.
 - No global state.
 - Lightweight, the only dependencies are Pygments, six and wcwidth.
-- Code written with love.
 - Runs on Linux, OS X, OpenBSD and Windows systems.
+- And much more...
 
 Feel free to create tickets for bugs and feature requests, and create pull
 requests if you have nice patches that you would like to share with others.
@@ -64,7 +64,7 @@ possible". Both Unix and Windows terminals have their limitations. But in
 general, the Unix experience will still be a little better.
 
 For Windows, it's recommended to use either `cmder
-<http://gooseberrycreative.com/cmder/>`_ or `conemu <https://conemu.github.io/>`_.
+<http://cmder.net/>`_ or `conemu <https://conemu.github.io/>`_.
 
 
 Installation
@@ -99,8 +99,9 @@ examples are chosen to demonstrate only one thing. Also, don't be afraid to
 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.
+Note for Python 2: all strings are expected to be unicode strings. So, either
+put a small ``u`` in front of every string or put ``from __future__ import
+unicode_literals`` at the start of the above example.
 
 
 Projects using prompt-toolkit
@@ -119,6 +120,8 @@ Shells:
 - `crash <https://github.com/crate/crash>`_:  Crate command line client.
 - `vcli <https://github.com/dbcli/vcli>`_: Vertica client.
 - `aws-shell <https://github.com/awslabs/aws-shell>`_: An integrated shell for working with the AWS CLI.
+- `softlayer-python <https://github.com/softlayer/softlayer-python>`_: A command-line interface to manage various SoftLayer products and services.
+- `ipython <http://github.com/ipython/ipython/>`_: The IPython REPL
 
 Full screen applications:
 
diff --git a/examples/autocompletion.py b/examples/autocompletion.py
index 1b20a90..6a6fbc9 100755
--- a/examples/autocompletion.py
+++ b/examples/autocompletion.py
@@ -3,8 +3,8 @@
 Autocompletion example.
 
 Press [Tab] to complete the current word.
-- The first Tab press fills in the common part of all completions.
-- The second Tab press shows all the completions. (In the menu)
+- 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 __future__ import unicode_literals
@@ -50,7 +50,8 @@ animal_completer = WordCompleter([
 
 
 def main():
-    text = prompt('Give some animals: ', completer=animal_completer)
+    text = prompt('Give some animals: ', completer=animal_completer,
+                  complete_while_typing=False)
     print('You said: %s' % text)
 
 
diff --git a/examples/bottom-toolbar.py b/examples/bottom-toolbar.py
index f5d1e7e..df5f9dc 100755
--- a/examples/bottom-toolbar.py
+++ b/examples/bottom-toolbar.py
@@ -4,11 +4,11 @@ Simple example showing a bottom toolbar.
 """
 from __future__ import unicode_literals
 from prompt_toolkit import prompt
-from prompt_toolkit.styles import PygmentsStyle
-from pygments.token import Token
+from prompt_toolkit.styles import style_from_dict
+from prompt_toolkit.token import Token
 
 
-test_style = PygmentsStyle.from_defaults({
+test_style = style_from_dict({
     Token.Toolbar: '#ffffff bg:#333333',
 })
 
diff --git a/examples/clock-input.py b/examples/clock-input.py
index afd978d..8d2ff24 100755
--- a/examples/clock-input.py
+++ b/examples/clock-input.py
@@ -3,14 +3,14 @@
 Example of a 'dynamic' prompt. On that shows the current time in the prompt.
 """
 from __future__ import unicode_literals
-from prompt_toolkit.interface import CommandLineInterface
 from prompt_toolkit.application import Application
+from prompt_toolkit.interface import CommandLineInterface
 from prompt_toolkit.layout import Window
 from prompt_toolkit.layout.controls import BufferControl
 from prompt_toolkit.layout.processors import BeforeInput
 from prompt_toolkit.shortcuts import create_eventloop
+from prompt_toolkit.token import Token
 from prompt_toolkit.utils import Callback
-from pygments.token import Token
 
 import datetime
 import time
diff --git a/examples/colored-prompt.py b/examples/colored-prompt.py
index 2d64e7c..881726e 100755
--- a/examples/colored-prompt.py
+++ b/examples/colored-prompt.py
@@ -5,11 +5,11 @@ Example of a colored prompt.
 from __future__ import unicode_literals
 
 from prompt_toolkit import prompt
-from prompt_toolkit.styles import PygmentsStyle
-from pygments.token import Token
+from prompt_toolkit.styles import style_from_dict
+from prompt_toolkit.token import Token
 
 
-example_style = PygmentsStyle.from_defaults(style_dict={
+example_style = style_from_dict({
     # User input.
     Token:          '#ff0066',
 
@@ -20,6 +20,10 @@ example_style = PygmentsStyle.from_defaults(style_dict={
     Token.Pound:    '#00aa00',
     Token.Host:     '#000088 bg:#aaaaff',
     Token.Path:     '#884444 underline',
+
+    # Make a selection reverse/underlined.
+    # (Use Control-Space to select.)
+    Token.SelectedText: 'reverse underline',
 })
 
 
diff --git a/examples/full-screen-layout.py b/examples/full-screen-layout.py
index 8b91f34..696079e 100755
--- a/examples/full-screen-layout.py
+++ b/examples/full-screen-layout.py
@@ -17,18 +17,17 @@ from prompt_toolkit.layout.containers import VSplit, HSplit, Window
 from prompt_toolkit.layout.controls import BufferControl, FillControl, TokenListControl
 from prompt_toolkit.layout.dimension import LayoutDimension as D
 from prompt_toolkit.shortcuts import create_eventloop
-
-from pygments.token import Token
+from prompt_toolkit.token import Token
 
 
 # 1. First we create the layout
 #    --------------------------
 
-# There are two types of classes that have to be combined to contruct a layout.
+# There are two types of classes that have to be combined to construct a layout.
 # We have containers and user controls. Simply said, containers are used for
 # arranging the layout, we have for instance `HSplit` and `VSplit`. And on the
 # other hand user controls paint the actual content. We have for instance
-# `BufferControl` and `TokenListControl`. An important interal difference is that
+# `BufferControl` and `TokenListControl`. An important internal difference is that
 # containers use absolute coordinates, while user controls paint on their own
 # `Screen` with a relative coordinates.
 
diff --git a/examples/get-multiline-input.py b/examples/get-multiline-input.py
index ef6e3ee..489c4b5 100755
--- a/examples/get-multiline-input.py
+++ b/examples/get-multiline-input.py
@@ -1,9 +1,19 @@
 #!/usr/bin/env python
 from __future__ import unicode_literals
 from prompt_toolkit import prompt
+from prompt_toolkit.token import Token
+
+
+def continuation_tokens(cli, width):
+    " The continuation: display dots before all the following lines. "
+
+    # (make sure that the width of the continuation does not exceed the given
+    # width. -- It is the prompt that decides the width of the left margin.)
+    return [(Token, '.' * (width - 1) + ' ')]
 
 
 if __name__ == '__main__':
     print('Press [Meta+Enter] or [Esc] followed by [Enter] to accept input.')
-    answer = prompt('Multiline input: ', multiline=True)
+    answer = prompt('Multiline input: ', multiline=True,
+                    get_continuation_tokens=continuation_tokens)
     print('You said: %s' % answer)
diff --git a/examples/html-input.py b/examples/html-input.py
index 678652a..ef2772c 100755
--- a/examples/html-input.py
+++ b/examples/html-input.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 """
 Simple example of a syntax-highlighted HTML input line.
+(This requires Pygments to be installed.)
 """
 from __future__ import unicode_literals
 from pygments.lexers import HtmlLexer
diff --git a/examples/print-tokens.py b/examples/print-tokens.py
new file mode 100755
index 0000000..cadbec1
--- /dev/null
+++ b/examples/print-tokens.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+"""
+Example of printing colored text to the output.
+"""
+from __future__ import unicode_literals
+from prompt_toolkit.shortcuts import print_tokens
+from prompt_toolkit.styles import style_from_dict
+from prompt_toolkit.token import Token
+
+
+def main():
+    style = style_from_dict({
+        Token.Hello: '#ff0066',
+        Token.World: '#44ff44 italic',
+    })
+    tokens = [
+        (Token.Hello, 'Hello '),
+        (Token.World, 'World'),
+        (Token, '\n'),
+    ]
+    print_tokens(tokens, style=style)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/examples/regular-language.py b/examples/regular-language.py
index e56d678..6d8a530 100755
--- a/examples/regular-language.py
+++ b/examples/regular-language.py
@@ -20,9 +20,8 @@ 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.layout.lexers import SimpleLexer
-from prompt_toolkit.styles import PygmentsStyle
-
-from pygments.token import Token
+from prompt_toolkit.styles import style_from_dict
+from prompt_toolkit.token import Token
 
 import math
 
@@ -38,7 +37,7 @@ def create_grammar():
     """)
 
 
-example_style = PygmentsStyle.from_defaults({
+example_style = style_from_dict({
     Token.Operator:       '#33aa33 bold',
     Token.Number:         '#aa3333 bold',
 
diff --git a/examples/rprompt.py b/examples/rprompt.py
new file mode 100755
index 0000000..8be220f
--- /dev/null
+++ b/examples/rprompt.py
@@ -0,0 +1,29 @@
+#!/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 __future__ import unicode_literals
+
+from prompt_toolkit import prompt
+from prompt_toolkit.styles import style_from_dict
+from prompt_toolkit.token import Token
+
+example_style = style_from_dict({
+    Token.RPrompt: 'bg:#ff0066 #ffffff',
+})
+
+
+def get_rprompt_tokens(cli):
+    return [
+        (Token, ' '),
+        (Token.RPrompt, '<rprompt>'),
+    ]
+
+
+if __name__ == '__main__':
+    answer = prompt('> ', get_rprompt_tokens=get_rprompt_tokens, style=example_style)
+    print('You said: %s' % answer)
diff --git a/examples/switch-between-vi-emacs.py b/examples/switch-between-vi-emacs.py
old mode 100644
new mode 100755
index 1ff40e8..4791f73
--- a/examples/switch-between-vi-emacs.py
+++ b/examples/switch-between-vi-emacs.py
@@ -1,8 +1,14 @@
+#!/usr/bin/env python
+"""
+Example that displays how to switch between Emacs and Vi input mode.
+
+"""
 from prompt_toolkit import prompt
 from prompt_toolkit.filters import Condition
 from prompt_toolkit.key_binding.manager import KeyBindingManager
 from prompt_toolkit.keys import Keys
-from pygments.token import Token
+from prompt_toolkit.styles import style_from_dict
+from prompt_toolkit.token import Token
 
 def run():
     vi_mode_enabled = False
@@ -19,6 +25,11 @@ def run():
         nonlocal vi_mode_enabled
         vi_mode_enabled = not vi_mode_enabled
 
+    # Add a bottom toolbar to display the status.
+    style = style_from_dict({
+        Token.Toolbar: 'reverse',
+    })
+
     def get_bottom_toolbar_tokens(cli):
         " Display the current input mode. "
         text = 'Vi' if vi_mode_enabled else 'Emacs'
@@ -27,6 +38,9 @@ def run():
         ]
 
     prompt('> ', key_bindings_registry=manager.registry,
-           get_bottom_toolbar_tokens=get_bottom_toolbar_tokens)
+           get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
+           style=style)
+
 
-run()
+if __name__ == '__main__':
+    run()
diff --git a/prompt_toolkit.egg-info/PKG-INFO b/prompt_toolkit.egg-info/PKG-INFO
index de7410c..ba464f9 100644
--- a/prompt_toolkit.egg-info/PKG-INFO
+++ b/prompt_toolkit.egg-info/PKG-INFO
@@ -1,11 +1,11 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
 Name: prompt-toolkit
-Version: 0.57
+Version: 0.60
 Summary: Library for building powerful interactive command lines in Python
 Home-page: https://github.com/jonathanslenders/python-prompt-toolkit
 Author: Jonathan Slenders
 Author-email: UNKNOWN
-License: LICENSE.txt
+License: UNKNOWN
 Description: Python Prompt Toolkit
         =====================
         
@@ -15,7 +15,7 @@ Description: Python Prompt Toolkit
         and terminal applications in Python.
         
         Read the `documentation on readthedocs
-        <http://python-prompt-toolkit.readthedocs.org/en/latest/>`_.
+        <http://python-prompt-toolkit.readthedocs.org/en/stable/>`_.
         
         
         Ptpython
@@ -51,8 +51,8 @@ Description: Python Prompt Toolkit
         - Multiple input buffers.
         - No global state.
         - Lightweight, the only dependencies are Pygments, six and wcwidth.
-        - Code written with love.
         - Runs on Linux, OS X, OpenBSD and Windows systems.
+        - And much more...
         
         Feel free to create tickets for bugs and feature requests, and create pull
         requests if you have nice patches that you would like to share with others.
@@ -72,7 +72,7 @@ Description: Python Prompt Toolkit
         general, the Unix experience will still be a little better.
         
         For Windows, it's recommended to use either `cmder
-        <http://gooseberrycreative.com/cmder/>`_ or `conemu <https://conemu.github.io/>`_.
+        <http://cmder.net/>`_ or `conemu <https://conemu.github.io/>`_.
         
         
         Installation
@@ -107,8 +107,9 @@ Description: Python Prompt Toolkit
         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.
+        Note for Python 2: all strings are expected to be unicode strings. So, either
+        put a small ``u`` in front of every string or put ``from __future__ import
+        unicode_literals`` at the start of the above example.
         
         
         Projects using prompt-toolkit
@@ -127,6 +128,8 @@ Description: Python Prompt Toolkit
         - `crash <https://github.com/crate/crash>`_:  Crate command line client.
         - `vcli <https://github.com/dbcli/vcli>`_: Vertica client.
         - `aws-shell <https://github.com/awslabs/aws-shell>`_: An integrated shell for working with the AWS CLI.
+        - `softlayer-python <https://github.com/softlayer/softlayer-python>`_: A command-line interface to manage various SoftLayer products and services.
+        - `ipython <http://github.com/ipython/ipython/>`_: The IPython REPL
         
         Full screen applications:
         
@@ -168,3 +171,16 @@ Description: Python Prompt Toolkit
             :alt: Latest Version
         
 Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: BSD License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python
+Classifier: Topic :: Software Development
diff --git a/prompt_toolkit.egg-info/SOURCES.txt b/prompt_toolkit.egg-info/SOURCES.txt
index eef38ee..c8a5061 100644
--- a/prompt_toolkit.egg-info/SOURCES.txt
+++ b/prompt_toolkit.egg-info/SOURCES.txt
@@ -33,7 +33,9 @@ examples/multiline-prompt.py
 examples/no-wrapping.py
 examples/patch-stdout.py
 examples/persistent-history.py
+examples/print-tokens.py
 examples/regular-language.py
+examples/rprompt.py
 examples/switch-between-vi-emacs.py
 examples/system-autocompletion.py
 examples/system-clipboard-integration.py
@@ -47,6 +49,7 @@ prompt_toolkit/application.py
 prompt_toolkit/auto_suggest.py
 prompt_toolkit/buffer.py
 prompt_toolkit/buffer_mapping.py
+prompt_toolkit/cache.py
 prompt_toolkit/completion.py
 prompt_toolkit/document.py
 prompt_toolkit/enums.py
@@ -61,7 +64,7 @@ prompt_toolkit/renderer.py
 prompt_toolkit/search_state.py
 prompt_toolkit/selection.py
 prompt_toolkit/shortcuts.py
-prompt_toolkit/styles.py
+prompt_toolkit/token.py
 prompt_toolkit/utils.py
 prompt_toolkit/validation.py
 prompt_toolkit/win32_types.py
@@ -123,7 +126,6 @@ prompt_toolkit/layout/__init__.py
 prompt_toolkit/layout/containers.py
 prompt_toolkit/layout/controls.py
 prompt_toolkit/layout/dimension.py
-prompt_toolkit/layout/highlighters.py
 prompt_toolkit/layout/lexers.py
 prompt_toolkit/layout/margins.py
 prompt_toolkit/layout/menus.py
@@ -133,6 +135,11 @@ prompt_toolkit/layout/prompt.py
 prompt_toolkit/layout/screen.py
 prompt_toolkit/layout/toolbars.py
 prompt_toolkit/layout/utils.py
+prompt_toolkit/styles/__init__.py
+prompt_toolkit/styles/base.py
+prompt_toolkit/styles/defaults.py
+prompt_toolkit/styles/from_dict.py
+prompt_toolkit/styles/from_pygments.py
 prompt_toolkit/terminal/__init__.py
 prompt_toolkit/terminal/conemu_output.py
 prompt_toolkit/terminal/vt100_input.py
@@ -140,12 +147,13 @@ prompt_toolkit/terminal/vt100_output.py
 prompt_toolkit/terminal/win32_input.py
 prompt_toolkit/terminal/win32_output.py
 tests/contrib_tests.py
+tests/filter_tests.py
 tests/run_tests.py
+tests/style_tests.py
 tests/buffer_tests/__init__.py
 tests/document_tests/__init__.py
 tests/inputstream_tests/__init__.py
 tests/key_binding_tests/__init__.py
 tests/layout_tests/__init__.py
 tests/regular_languages_tests/__init__.py
-tests/screen_tests/__init__.py
 tests/utils_tests/__init__.py
\ No newline at end of file
diff --git a/prompt_toolkit.egg-info/requires.txt b/prompt_toolkit.egg-info/requires.txt
index b494145..5022c45 100644
--- a/prompt_toolkit.egg-info/requires.txt
+++ b/prompt_toolkit.egg-info/requires.txt
@@ -1,3 +1,2 @@
-pygments
 six>=1.9.0
 wcwidth
diff --git a/prompt_toolkit/__init__.py b/prompt_toolkit/__init__.py
index 840e976..d4d23b5 100644
--- a/prompt_toolkit/__init__.py
+++ b/prompt_toolkit/__init__.py
@@ -18,4 +18,5 @@ from .application import AbortAction, Application
 from .shortcuts import prompt
 
 
-__version__ = '0.57'
+# Don't forget to update in `docs/conf.py`!
+__version__ = '0.60'
diff --git a/prompt_toolkit/application.py b/prompt_toolkit/application.py
index e8daab4..c23fa1f 100644
--- a/prompt_toolkit/application.py
+++ b/prompt_toolkit/application.py
@@ -73,6 +73,7 @@ class Application(object):
     :param on_buffer_changed: Called when the content of a buffer has been changed.
     :param on_initialize: Called after the
         :class:`~prompt_toolkit.interface.CommandLineInterface` initializes.
+    :param on_render: Called right after rendering.
     """
     def __init__(self, layout=None, buffer=None, buffers=None,
                  initial_focussed_buffer=DEFAULT_BUFFER,
@@ -85,7 +86,7 @@ class Application(object):
                  paste_mode=False, ignore_case=False,
 
                  on_input_timeout=None, on_start=None, on_stop=None,
-                 on_reset=None, on_initialize=None, on_buffer_changed=None):
+                 on_reset=None, on_initialize=None, on_buffer_changed=None, on_render=None):
 
         paste_mode = to_cli_filter(paste_mode)
         ignore_case = to_cli_filter(ignore_case)
@@ -107,6 +108,7 @@ class Application(object):
         assert on_reset is None or isinstance(on_reset, Callback)
         assert on_buffer_changed is None or isinstance(on_buffer_changed, Callback)
         assert on_initialize is None or isinstance(on_initialize, Callback)
+        assert on_render is None or isinstance(on_render, Callback)
         assert style is None or isinstance(style, Style)
 
         self.layout = layout or Window(BufferControl())
@@ -150,3 +152,4 @@ class Application(object):
         self.on_reset = on_reset or Callback()
         self.on_initialize = on_initialize or Callback()
         self.on_buffer_changed = on_buffer_changed or Callback()
+        self.on_render = on_render or Callback()
diff --git a/prompt_toolkit/buffer.py b/prompt_toolkit/buffer.py
index f692819..0dc26c6 100644
--- a/prompt_toolkit/buffer.py
+++ b/prompt_toolkit/buffer.py
@@ -14,8 +14,11 @@ from .history import History, InMemoryHistory
 from .search_state import SearchState
 from .selection import SelectionType, SelectionState
 from .utils import Callback
+from .cache import FastDictCache
 from .validation import ValidationError
 
+from six.moves import range
+
 import os
 import six
 import subprocess
@@ -29,6 +32,7 @@ __all__ = (
     'unindent',
 )
 
+
 class EditReadOnlyBuffer(Exception):
     " Attempt editing of read-only :class:`.Buffer`. "
 
@@ -42,8 +46,6 @@ class AcceptAction(object):
         :class:`~prompt_toolkit.interface.CommandLineInterface` and
         :class:`~prompt_toolkit.document.Document`. It is called when the user
         accepts input.
-    :param render_cli_done: When using a handler, first render the CLI in the
-        'done' state, then call the handler. This
     """
     def __init__(self, handler=None):
         assert handler is None or callable(handler)
@@ -225,6 +227,9 @@ class Buffer(object):
         self.on_text_insert = on_text_insert or Callback()
         self.on_cursor_position_changed = on_cursor_position_changed or Callback()
 
+        # Document cache. (Avoid creating new Document instances.)
+        self._document_cache = FastDictCache(Document, size=10)
+
         self.reset(initial_document=initial_document)
 
     def reset(self, initial_document=None, append_to_history=False):
@@ -273,10 +278,23 @@ class Buffer(object):
 
     def _set_text(self, value):
         """ set text at current working_index. Return whether it changed. """
-        original_value = self._working_lines[self.working_index]
-        self._working_lines[self.working_index] = value
-
-        return value != original_value
+        working_index = self.working_index
+        working_lines = self._working_lines
+
+        original_value = working_lines[working_index]
+        working_lines[working_index] = value
+
+        # Return True when this text has been changed.
+        if len(value) != len(original_value):
+            # For Python 2, it seems that when two strings have a different
+            # length and one is a prefix of the other, Python still scans
+            # character by character to see whether the strings are different.
+            # (Some benchmarking showed significant differences for big
+            # documents. >100,000 of lines.)
+            return True
+        elif value != original_value:
+            return True
+        return False
 
     def _set_cursor_position(self, value):
         """ Set cursor position. Return whether it changed. """
@@ -363,9 +381,10 @@ class Buffer(object):
     def document(self):
         """
         Return :class:`~prompt_toolkit.document.Document` instance from the
-        current text and cursor position.
+        current text, cursor position and selection state.
         """
-        return Document(self.text, self.cursor_position, selection=self.selection_state)
+        return self._document_cache[
+            self.text, self.cursor_position, self.selection_state]
 
     @document.setter
     def document(self, value):
@@ -861,16 +880,21 @@ class Buffer(object):
         :param fire_event: Fire `on_text_insert` event. This is mainly used to
             trigger autocompletion while typing.
         """
+        # Original text & cursor position.
+        otext = self.text
+        ocpos = self.cursor_position
+
         # In insert/text mode.
         if overwrite:
-            # Don't overwrite the newline itself. Just before the line ending, it should act like insert mode.
-            overwritten_text = self.text[self.cursor_position:self.cursor_position+len(data)]
+            # Don't overwrite the newline itself. Just before the line ending,
+            # it should act like insert mode.
+            overwritten_text = otext[ocpos:ocpos + len(data)]
             if '\n' in overwritten_text:
                 overwritten_text = overwritten_text[:overwritten_text.find('\n')]
 
-            self.text = self.text[:self.cursor_position] + data + self.text[self.cursor_position+len(overwritten_text):]
+            self.text = otext[:ocpos] + data + otext[ocpos + len(overwritten_text):]
         else:
-            self.text = self.text[:self.cursor_position] + data + self.text[self.cursor_position:]
+            self.text = otext[:ocpos] + data + otext[ocpos:]
 
         if move_cursor:
             self.cursor_position += len(data)
@@ -1001,7 +1025,7 @@ class Buffer(object):
         for _ in range(count):
             result = search_once(working_index, document)
             if result is None:
-                return # Nothing found.
+                return  # Nothing found.
             else:
                 working_index, document = result
 
@@ -1025,8 +1049,8 @@ class Buffer(object):
         Apply search. If something is found, set `working_index` and
         `cursor_position`.
         """
-        search_result = self._search(search_state,
-            include_current_position=include_current_position, count=count)
+        search_result = self._search(
+            search_state, include_current_position=include_current_position, count=count)
 
         if search_result is not None:
             working_index, cursor_position = search_result
diff --git a/prompt_toolkit/cache.py b/prompt_toolkit/cache.py
new file mode 100644
index 0000000..37961bf
--- /dev/null
+++ b/prompt_toolkit/cache.py
@@ -0,0 +1,86 @@
+from __future__ import unicode_literals
+from collections import deque
+
+__all__ = (
+    'SimpleCache',
+    'FastDictCache',
+)
+
+
+class SimpleCache(object):
+    """
+    Very simple cache that discards the oldest item when the cache size is
+    exceeded.
+
+    :param maxsize: Maximum size of the cache. (Don't make it too big.)
+    """
+    def __init__(self, maxsize=8):
+        assert isinstance(maxsize, int) and maxsize > 0
+
+        self._data = {}
+        self._keys = deque()
+        self.maxsize = maxsize
+
+    def get(self, key, getter_func):
+        """
+        Get object from the cache.
+        If not found, call `getter_func` to resolve it, and put that on the top
+        of the cache instead.
+        """
+        # Look in cache first.
+        try:
+            return self._data[key]
... 7857 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