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

Scott Kitterman kitterman at moszumanska.debian.org
Fri Nov 11 01:56:12 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 10186fda1a1c8a774e37ce7fc8611124aaa29d88
Author: Scott Kitterman <scott at kitterman.com>
Date:   Thu Nov 10 20:49:46 2016 -0500

    Import prompt-toolkit_1.0.9.orig.tar.gz
---
 CHANGELOG                                          |  17 ++++
 PKG-INFO                                           |   2 +-
 examples/full-screen-layout.py                     |   2 +-
 prompt_toolkit.egg-info/PKG-INFO                   |   2 +-
 prompt_toolkit.egg-info/SOURCES.txt                |   3 +-
 prompt_toolkit/__init__.py                         |   4 +-
 prompt_toolkit/buffer.py                           | 110 ++++++++++++++++++++-
 prompt_toolkit/eventloop/posix.py                  |   9 +-
 prompt_toolkit/interface.py                        |   1 -
 prompt_toolkit/key_binding/bindings/basic.py       |  14 +--
 prompt_toolkit/key_binding/bindings/emacs.py       |  25 ++---
 .../key_binding/bindings/named_commands.py         |  19 ++++
 prompt_toolkit/key_binding/bindings/vi.py          |  58 +++++++----
 prompt_toolkit/key_binding/input_processor.py      |   7 ++
 prompt_toolkit/terminal/vt100_input.py             |  10 +-
 prompt_toolkit/terminal/vt100_output.py            |  95 +++++++++---------
 prompt_toolkit/terminal/win32_output.py            |  37 ++++---
 tests/test_yank_nth_arg.py                         |  85 ++++++++++++++++
 18 files changed, 369 insertions(+), 131 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 181efc6..a584447 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,23 @@
 CHANGELOG
 =========
 
+1.0.9: 2016-11-07
+-----------------
+
+Fixes:
+- Fixed a bug in the `cooked_mode` context manager. This caused a bug in
+  ptpython where executing `input()` would display ^M instead of accepting the
+  input.
+- Handle race condition in eventloop/posix.py
+- Updated ANSI color names for vt100. (High and low intensity colors were
+  swapped.)
+
+New features:
+- Added yank-nth-arg and yank-last-arg readline commands + Emacs bindings.
+- Allow searching in Vi selection mode.
+- Made text objects of the Vi 'n' and 'N' search bindings. This adds for
+  instance the following bindings: cn, cN, dn, dN, yn, yN
+
 1.0.8: 2016-10-16
 -----------------
 
diff --git a/PKG-INFO b/PKG-INFO
index 7907dd9..7173e68 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: prompt_toolkit
-Version: 1.0.8
+Version: 1.0.9
 Summary: Library for building powerful interactive command lines in Python
 Home-page: https://github.com/jonathanslenders/python-prompt-toolkit
 Author: Jonathan Slenders
diff --git a/examples/full-screen-layout.py b/examples/full-screen-layout.py
index 6883d28..f9e6ea1 100755
--- a/examples/full-screen-layout.py
+++ b/examples/full-screen-layout.py
@@ -141,7 +141,7 @@ buffers={
 # Now we add an event handler that captures change events to the buffer on the
 # left. If the text changes over there, we'll update the buffer on the right.
 
-def default_buffer_changed(cli):
+def default_buffer_changed(default_buffer):
     """
     When the buffer on the left (DEFAULT_BUFFER) changes, update the buffer on
     the right. We just reverse the text.
diff --git a/prompt_toolkit.egg-info/PKG-INFO b/prompt_toolkit.egg-info/PKG-INFO
index d8f089f..718a00c 100644
--- a/prompt_toolkit.egg-info/PKG-INFO
+++ b/prompt_toolkit.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: prompt-toolkit
-Version: 1.0.8
+Version: 1.0.9
 Summary: Library for building powerful interactive command lines in Python
 Home-page: https://github.com/jonathanslenders/python-prompt-toolkit
 Author: Jonathan Slenders
diff --git a/prompt_toolkit.egg-info/SOURCES.txt b/prompt_toolkit.egg-info/SOURCES.txt
index 8c9079b..1298a22 100644
--- a/prompt_toolkit.egg-info/SOURCES.txt
+++ b/prompt_toolkit.egg-info/SOURCES.txt
@@ -163,4 +163,5 @@ tests/test_layout.py
 tests/test_regular_languages.py
 tests/test_shortcuts.py
 tests/test_style.py
-tests/test_utils.py
\ No newline at end of file
+tests/test_utils.py
+tests/test_yank_nth_arg.py
\ No newline at end of file
diff --git a/prompt_toolkit/__init__.py b/prompt_toolkit/__init__.py
index 57d6c1e..a8d0203 100644
--- a/prompt_toolkit/__init__.py
+++ b/prompt_toolkit/__init__.py
@@ -15,8 +15,8 @@ Probably, to get started, you meight also want to have a look at
 """
 from .interface import CommandLineInterface
 from .application import AbortAction, Application
-from .shortcuts import prompt
+from .shortcuts import prompt, prompt_async
 
 
 # Don't forget to update in `docs/conf.py`!
-__version__ = '1.0.8'
+__version__ = '1.0.9'
diff --git a/prompt_toolkit/buffer.py b/prompt_toolkit/buffer.py
index 5b821fe..fc25db8 100644
--- a/prompt_toolkit/buffer.py
+++ b/prompt_toolkit/buffer.py
@@ -150,6 +150,24 @@ class CompletionState(object):
             return self.current_completions[self.complete_index]
 
 
+_QUOTED_WORDS_RE = re.compile(r"""(\s+|".*?"|'.*?')""")
+
+
+class YankNthArgState(object):
+    """
+    For yank-last-arg/yank-nth-arg: Keep track of where we are in the history.
+    """
+    def __init__(self, history_position=0, n=-1, previous_inserted_word=''):
+        self.history_position = history_position
+        self.previous_inserted_word = previous_inserted_word
+        self.n = n
+
+    def __repr__(self):
+        return '%s(history_position=%r, n=%r, previous_inserted_word=%r)' % (
+            self.__class__.__name__, self.history_position, self.n,
+            self.previous_inserted_word)
+
+
 class Buffer(object):
     """
     The core data structure that holds the text and cursor position of the
@@ -267,6 +285,9 @@ class Buffer(object):
         # State of complete browser
         self.complete_state = None  # For interactive completion through Ctrl-N/Ctrl-P.
 
+        # State of Emacs yank-nth-arg completion.
+        self.yank_nth_arg_state = None  # for yank-nth-arg.
+
         # Current suggestion.
         self.suggestion = None
 
@@ -373,6 +394,7 @@ class Buffer(object):
         # Remove any validation errors and complete state.
         self.validation_error = None
         self.complete_state = None
+        self.yank_nth_arg_state = None
         self.selection_state = None
         self.suggestion = None
         self.preferred_column = None
@@ -384,6 +406,7 @@ class Buffer(object):
         # Remove any validation errors and complete state.
         self.validation_error = None
         self.complete_state = None
+        self.yank_nth_arg_state = None
 
         # Unset preferred_column. (Will be set after the cursor movement, if
         # required.)
@@ -859,6 +882,63 @@ class Buffer(object):
         if found_something:
             self.cursor_position = len(self.text)
 
+    def yank_nth_arg(self, n=None, _yank_last_arg=False):
+        """
+        Pick nth word from previous history entry (depending on current
+        `yank_nth_arg_state`) and insert it at current position. Rotate through
+        history if called repeatedly. If no `n` has been given, take the first
+        argument. (The second word.)
+
+        :param n: (None or int), The index of the word from the previous line
+            to take.
+        """
+        assert n is None or isinstance(n, int)
+
+        if not len(self.history):
+            return
+
+        # Make sure we have a `YankNthArgState`.
+        if self.yank_nth_arg_state is None:
+            state = YankNthArgState(n=-1 if _yank_last_arg else 1)
+        else:
+            state = self.yank_nth_arg_state
+
+        if n is not None:
+            state.n = n
+
+        # Get new history position.
+        new_pos = state.history_position - 1
+        if -new_pos > len(self.history):
+            new_pos = -1
+
+        # Take argument from line.
+        line = self.history[new_pos]
+
+        words = [w.strip() for w in _QUOTED_WORDS_RE.split(line)]
+        words = [w for w in words if w]
+        try:
+            word = words[state.n]
+        except IndexError:
+            word = ''
+
+        # Insert new argument.
+        if state.previous_inserted_word:
+            self.delete_before_cursor(len(state.previous_inserted_word))
+        self.insert_text(word)
+
+        # Save state again for next completion. (Note that the 'insert'
+        # operation from above clears `self.yank_nth_arg_state`.)
+        state.previous_inserted_word = word
+        state.history_position = new_pos
+        self.yank_nth_arg_state = state
+
+    def yank_last_arg(self, n=None):
+        """
+        Like `yank_nth_arg`, but if no argument has been given, yank the last
+        word by default.
+        """
+        self.yank_nth_arg(n=n, _yank_last_arg=True)
+
     def start_selection(self, selection_type=SelectionType.CHARACTERS):
         """
         Take the current cursor position as the start of this selection.
@@ -1084,7 +1164,10 @@ class Buffer(object):
     def document_for_search(self, search_state):
         """
         Return a :class:`~prompt_toolkit.document.Document` instance that has
-        the text/cursor position for this search, if we would apply it.
+        the text/cursor position for this search, if we would apply it. This
+        will be used in the
+        :class:`~prompt_toolkit.layout.controls.BufferControl` to display
+        feedback while searching.
         """
         search_result = self._search(search_state, include_current_position=True)
 
@@ -1092,7 +1175,30 @@ class Buffer(object):
             return self.document
         else:
             working_index, cursor_position = search_result
-            return Document(self._working_lines[working_index], cursor_position)
+
+            # Keep selection, when `working_index` was not changed.
+            if working_index == self.working_index:
+                selection = self.selection_state
+            else:
+                selection = None
+
+            return Document(self._working_lines[working_index],
+                            cursor_position, selection=selection)
+
+    def get_search_position(self, search_state, include_current_position=True, count=1):
+        """
+        Get the cursor position for this search.
+        (This operation won't change the `working_index`. It's won't go through
+        the history. Vi text objects can't span multiple items.)
+        """
+        search_result = self._search(
+            search_state, include_current_position=include_current_position, count=count)
+
+        if search_result is None:
+            return self.cursor_position
+        else:
+            working_index, cursor_position = search_result
+            return cursor_position
 
     def apply_search(self, search_state, include_current_position=True, count=1):
         """
diff --git a/prompt_toolkit/eventloop/posix.py b/prompt_toolkit/eventloop/posix.py
index 0262f4d..9ca3fc9 100644
--- a/prompt_toolkit/eventloop/posix.py
+++ b/prompt_toolkit/eventloop/posix.py
@@ -244,7 +244,14 @@ class PosixEventLoop(EventLoop):
         self._calls_from_executor.append((callback, _max_postpone_until))
 
         if self._schedule_pipe:
-            os.write(self._schedule_pipe[1], b'x')
+            try:
+                os.write(self._schedule_pipe[1], b'x')
+            except (AttributeError, IndexError, OSError):
+                # Handle race condition. We're in a different thread.
+                # - `_schedule_pipe` could have become None in the meantime.
+                # - We catch `OSError` (actually BrokenPipeError), because the
+                #   main thread could have closed the pipe already.
+                pass
 
     def stop(self):
         """
diff --git a/prompt_toolkit/interface.py b/prompt_toolkit/interface.py
index f1a7b62..458c85d 100644
--- a/prompt_toolkit/interface.py
+++ b/prompt_toolkit/interface.py
@@ -620,7 +620,6 @@ class CommandLineInterface(object):
         with self.input.cooked_mode():
             result = func()
 
-
         # Redraw interface again.
         self.renderer.reset()
         self.renderer.request_absolute_cursor_position()
diff --git a/prompt_toolkit/key_binding/bindings/basic.py b/prompt_toolkit/key_binding/bindings/basic.py
index 2d9de77..03b9964 100644
--- a/prompt_toolkit/key_binding/bindings/basic.py
+++ b/prompt_toolkit/key_binding/bindings/basic.py
@@ -162,7 +162,7 @@ def load_basic_bindings(registry, filter=Always()):
     is_multiline = Condition(lambda cli: cli.current_buffer.is_multiline())
     is_returnable = Condition(lambda cli: cli.current_buffer.accept_action.is_returnable)
 
-    @handle(Keys.ControlJ, filter=is_multiline)
+    @handle(Keys.ControlJ, filter=is_multiline & insert_mode)
     def _(event):
         " Newline (in case of multiline input. "
         event.current_buffer.newline(copy_margin=not event.cli.in_paste_mode)
@@ -175,22 +175,14 @@ def load_basic_bindings(registry, filter=Always()):
 
     # Delete the word before the cursor.
 
-    @handle(Keys.Up, filter= ~has_selection)
+    @handle(Keys.Up)
     def _(event):
         event.current_buffer.auto_up(count=event.arg)
 
-    @handle(Keys.Up, filter=has_selection)
-    def _(event):
-        event.current_buffer.cursor_up(count=event.arg)
-
-    @handle(Keys.Down, filter= ~has_selection)
+    @handle(Keys.Down)
     def _(event):
         event.current_buffer.auto_down(count=event.arg)
 
-    @handle(Keys.Down, filter=has_selection)
-    def _(event):
-        event.current_buffer.cursor_down(count=event.arg)
-
     @handle(Keys.Delete, filter=has_selection)
     def _(event):
         data = event.current_buffer.cut_selection()
diff --git a/prompt_toolkit/key_binding/bindings/emacs.py b/prompt_toolkit/key_binding/bindings/emacs.py
index ba99cba..d23161f 100644
--- a/prompt_toolkit/key_binding/bindings/emacs.py
+++ b/prompt_toolkit/key_binding/bindings/emacs.py
@@ -71,31 +71,25 @@ def load_emacs_bindings(registry, filter=Always()):
     handle(Keys.Escape, '<', filter= ~has_selection)(get_by_name('beginning-of-history'))
     handle(Keys.Escape, '>', filter= ~has_selection)(get_by_name('end-of-history'))
 
-    @handle(Keys.ControlN, filter= ~has_selection)
+    handle(Keys.Escape, '.', filter=insert_mode)(get_by_name('yank-last-arg'))
+    handle(Keys.Escape, '_', filter=insert_mode)(get_by_name('yank-last-arg'))
+    handle(Keys.Escape, Keys.ControlY, filter=insert_mode)(get_by_name('yank-nth-arg'))
+
+    @handle(Keys.ControlN)
     def _(event):
         " Next line. "
         event.current_buffer.auto_down()
 
-    @handle(Keys.ControlN, filter=has_selection)
-    def _(event):
-        " Next line (but don't cycle through history.) "
-        event.current_buffer.cursor_down()
-
     @handle(Keys.ControlO, filter=insert_mode)
     def _(event):
         " Insert newline, but don't move the cursor. "
         event.current_buffer.insert_text('\n', move_cursor=False)
 
-    @handle(Keys.ControlP, filter= ~has_selection)
+    @handle(Keys.ControlP)
     def _(event):
         " Previous line. "
         event.current_buffer.auto_up(count=event.arg)
 
-    @handle(Keys.ControlP, filter=has_selection)
-    def _(event):
-        " Previous line. "
-        event.current_buffer.cursor_up(count=event.arg)
-
     @handle(Keys.ControlQ, Keys.Any, filter= ~has_selection)
     def _(event):
         """
@@ -178,13 +172,6 @@ def load_emacs_bindings(registry, filter=Always()):
         """
         # TODO
 
-    @handle(Keys.Escape, '.', filter=insert_mode)
-    def _(event):
-        """
-        Rotate through the last word (white-space delimited) of the previous lines in history.
-        """
-        # TODO
-
     @handle(Keys.Escape, '*', filter=insert_mode)
     def _(event):
         """
diff --git a/prompt_toolkit/key_binding/bindings/named_commands.py b/prompt_toolkit/key_binding/bindings/named_commands.py
index 2f587cd..40ed198 100644
--- a/prompt_toolkit/key_binding/bindings/named_commands.py
+++ b/prompt_toolkit/key_binding/bindings/named_commands.py
@@ -366,6 +366,25 @@ def yank(event):
     event.current_buffer.paste_clipboard_data(
         event.cli.clipboard.get_data(), count=event.arg, before=True)
 
+ at register('yank-nth-arg')
+def yank_nth_arg(event):
+    """
+    Insert the first argument of the previous command. With an argument, insert
+    the nth word from the previous command (start counting at 0).
+    """
+    n = (event.arg if event.arg_present else None)
+    event.current_buffer.yank_nth_arg(n)
+
+
+ at register('yank-last-arg')
+def yank_last_arg(event):
+    """
+    Like `yank_nth_arg`, but if no argument has been given, yank the last word
+    of each line.
+    """
+    n = (event.arg if event.arg_present else None)
+    event.current_buffer.yank_last_arg(n)
+
 #
 # Completion.
 #
diff --git a/prompt_toolkit/key_binding/bindings/vi.py b/prompt_toolkit/key_binding/bindings/vi.py
index 6185573..8d353c4 100644
--- a/prompt_toolkit/key_binding/bindings/vi.py
+++ b/prompt_toolkit/key_binding/bindings/vi.py
@@ -476,24 +476,6 @@ def load_vi_bindings(registry, enable_visual_key=Always(),
         " Join selected lines without space. "
         event.current_buffer.join_selected_lines(separator='')
 
-    @handle('n', filter=navigation_mode)
-    def _(event):  # XXX: use `text_object`
-        """
-        Search next.
-        """
-        event.current_buffer.apply_search(
-            get_search_state(event.cli), include_current_position=False,
-            count=event.arg)
-
-    @handle('N', filter=navigation_mode)
-    def _(event):  # TODO: use `text_object`
-        """
-        Search previous.
-        """
-        event.current_buffer.apply_search(
-            ~get_search_state(event.cli), include_current_position=False,
-            count=event.arg)
-
     @handle('p', filter=navigation_mode)
     def _(event):
         """
@@ -1336,6 +1318,38 @@ def load_vi_bindings(registry, enable_visual_key=Always(),
             pos = len(b.document.text_after_cursor)
         return TextObject(pos, type=TextObjectType.LINEWISE)
 
+    @text_object('n', no_move_handler=True)
+    def _(event):
+        " Search next. "
+        buff = event.current_buffer
+        cursor_position = buff.get_search_position(
+            get_search_state(event.cli), include_current_position=False,
+            count=event.arg)
+        return TextObject(cursor_position - buff.cursor_position)
+
+    @handle('n', filter=navigation_mode)
+    def _(event):
+        " Search next in navigation mode. (This goes through the history.) "
+        event.current_buffer.apply_search(
+            get_search_state(event.cli), include_current_position=False,
+            count=event.arg)
+
+    @text_object('N', no_move_handler=True)
+    def _(event):
+        " Search previous. "
+        buff = event.current_buffer
+        cursor_position = buff.get_search_position(
+            ~get_search_state(event.cli), include_current_position=False,
+            count=event.arg)
+        return TextObject(cursor_position - buff.cursor_position)
+
+    @handle('N', filter=navigation_mode)
+    def _(event):
+        " Search previous in navigation mode. (This goes through the history.) "
+        event.current_buffer.apply_search(
+            ~get_search_state(event.cli), include_current_position=False,
+            count=event.arg)
+
     @handle('z', '+', filter=navigation_mode|selection_mode)
     @handle('z', 't', filter=navigation_mode|selection_mode)
     @handle('z', Keys.ControlJ, filter=navigation_mode|selection_mode)
@@ -1595,7 +1609,8 @@ def load_vi_bindings(registry, enable_visual_key=Always(),
 
         for p2 in buff.multiple_cursor_positions:
             text.append(original_text[p:p2])
-            if original_text[p2] == '\n':  # Don't delete across lines.
+            if p2 >= len(original_text) or original_text[p2] == '\n':
+                # Don't delete across lines.
                 p = p2
             else:
                 p = p2 + 1
@@ -1727,9 +1742,10 @@ def load_vi_search_bindings(registry, get_search_state=None,
 
     has_focus = filters.HasFocus(search_buffer_name)
     navigation_mode = ViNavigationMode()
+    selection_mode = ViSelectionMode()
     handle = create_handle_decorator(registry, filter & ViMode())
 
-    @handle('/', filter=navigation_mode)
+    @handle('/', filter=navigation_mode|selection_mode)
     @handle(Keys.ControlS, filter=~has_focus)
     def _(event):
         """
@@ -1742,7 +1758,7 @@ def load_vi_search_bindings(registry, get_search_state=None,
         # Focus search buffer.
         event.cli.push_focus(search_buffer_name)
 
-    @handle('?', filter=navigation_mode)
+    @handle('?', filter=navigation_mode|selection_mode)
     @handle(Keys.ControlR, filter=~has_focus)
     def _(event):
         """
diff --git a/prompt_toolkit/key_binding/input_processor.py b/prompt_toolkit/key_binding/input_processor.py
index c23c76d..ffe7ac1 100644
--- a/prompt_toolkit/key_binding/input_processor.py
+++ b/prompt_toolkit/key_binding/input_processor.py
@@ -321,6 +321,13 @@ class KeyPressEvent(object):
 
         return result
 
+    @property
+    def arg_present(self):
+        """
+        True if repetition argument was explicitly provided.
+        """
+        return self._arg is not None
+
     def append_to_arg_count(self, data):
         """
         Add digit to the input argument.
diff --git a/prompt_toolkit/terminal/vt100_input.py b/prompt_toolkit/terminal/vt100_input.py
index ec8a8d8..f65909d 100644
--- a/prompt_toolkit/terminal/vt100_input.py
+++ b/prompt_toolkit/terminal/vt100_input.py
@@ -490,7 +490,8 @@ class raw_mode(object):
 
 class cooked_mode(raw_mode):
     """
-    (The opposide of ``raw_mode``::
+    The opposide of ``raw_mode``, used when we need cooked mode inside a
+    `raw_mode` block.  Used in `CommandLineInterface.run_in_terminal`.::
 
         with cooked_mode(stdin):
             ''' the pseudo-terminal stdin is now used in cooked mode. '''
@@ -501,5 +502,8 @@ class cooked_mode(raw_mode):
 
     @classmethod
     def _patch_iflag(cls, attrs):
-        # Don't change any.
-        return attrs
+        # Turn the ICRNL flag back on. (Without this, calling `input()` in
+        # run_in_terminal doesn't work and displays ^M instead. Ptpython
+        # evaluates commands using `run_in_terminal`, so it's important that
+        # they translate ^M back into ^J.)
+        return attrs | termios.ICRNL
diff --git a/prompt_toolkit/terminal/vt100_output.py b/prompt_toolkit/terminal/vt100_output.py
index 5275798..4568ee3 100644
--- a/prompt_toolkit/terminal/vt100_output.py
+++ b/prompt_toolkit/terminal/vt100_output.py
@@ -25,77 +25,76 @@ __all__ = (
 
 
 FG_ANSI_COLORS = {
-    'ansiblack':   30,
     'ansidefault': 39,
+    'ansiblack':   30,
+    'ansidarkgray': 37,
+    'ansilightgray':90,
     'ansiwhite':   97,
 
     # Low intensity.
-    'ansired':         31,
-    'ansigreen':       32,
-    'ansiyellow':      33,
-    'ansiblue':        34,
-    'ansifuchsia':     35,
-    'ansiturquoise':   36,
-    'ansilightgray':   37,
-
+    'ansidarkred':     31,
+    'ansidarkgreen':   32,
+    'ansibrown':       33,
+    'ansidarkblue':    34,
+    'ansipurple':      35,
+    'ansiteal':        36,
 
     # High intensity.
-    'ansidarkgray':    90,  # Bright black.
-    'ansidarkred':     91,
-    'ansidarkgreen':   92,
-    'ansibrown':       93,
-    'ansidarkblue':    94,
-    'ansipurple':      95,
-    'ansiteal':        96,
+    'ansired':         91,
+    'ansigreen':       92,
+    'ansiyellow':      93,
+    'ansiblue':        94,
+    'ansifuchsia':     95,
+    'ansiturquoise':   96,
 }
 
 BG_ANSI_COLORS = {
-    'ansiblack':       40,
     'ansidefault':     49,
+    'ansiblack':       40,
+    'ansidarkgray':    47,
     'ansiwhite':       107,
+    'ansilightgray':   100,
 
     # Low intensity.
-    'ansired':         41,
-    'ansigreen':       42,
-    'ansiyellow':      43,
-    'ansiblue':        44,
-    'ansifuchsia':     45,
-    'ansiturquoise':   46,
-    'ansilightgray':   47,
+    'ansidarkred':     41,
+    'ansidarkgreen':   42,
+    'ansibrown':       43,
+    'ansidarkblue':    44,
+    'ansipurple':      45,
+    'ansiteal':        46,
 
     # High intensity.
-    'ansidarkgray':    100,  # bright black.
-    'ansidarkred':     101,
-    'ansidarkgreen':   102,
-    'ansibrown':       103,
-    'ansidarkblue':    104,
-    'ansipurple':      105,
-    'ansiteal':        106,
+    'ansired':         101,
+    'ansigreen':       102,
+    'ansiyellow':      103,
+    'ansiblue':        104,
+    'ansifuchsia':     105,
+    'ansiturquoise':   106,
 }
 
 
 ANSI_COLORS_TO_RGB = {
-    'ansiblack':   (0x00, 0x00, 0x00),
-    'ansidefault': (0x00, 0x00, 0x00),  # Don't use, 'default' doesn't really have a value.
-    'ansiwhite':   (0xff, 0xff, 0xff),
+    'ansidefault':   (0x00, 0x00, 0x00),  # Don't use, 'default' doesn't really have a value.
+    'ansiblack':     (0x00, 0x00, 0x00),
+    'ansidarkgray':  (0x7f, 0x7f, 0x7f), 
+    'ansiwhite':     (0xff, 0xff, 0xff),
+    'ansilightgray': (0xe5, 0xe5, 0xe5),
 
     # Low intensity.
-    'ansired':         (0xcd, 0x00, 0x00),
-    'ansigreen':       (0x00, 0xcd, 0x00),
-    'ansiyellow':      (0xcd, 0xcd, 0x00),
-    'ansiblue':        (0x00, 0x00, 0xcd),
-    'ansifuchsia':     (0xcd, 0x00, 0xcd),
-    'ansiturquoise':   (0x00, 0xcd, 0xcd),
-    'ansilightgray':   (0xe5, 0xe5, 0xe5),
+    'ansidarkred':     (0xcd, 0x00, 0x00),
+    'ansidarkgreen':   (0x00, 0xcd, 0x00),
+    'ansibrown':       (0xcd, 0xcd, 0x00),
+    'ansidarkblue':    (0x00, 0x00, 0xcd),
+    'ansipurple':      (0xcd, 0x00, 0xcd),
+    'ansiteal':        (0x00, 0xcd, 0xcd),
 
     # High intensity.
-    'ansidarkgray':    (0x7f, 0x7f, 0x7f),  # Bright black.
-    'ansidarkred':     (0xff, 0x00, 0x00),
-    'ansidarkgreen':   (0x00, 0xff, 0x00),
-    'ansibrown':       (0xff, 0xff, 0x00),
-    'ansidarkblue':    (0x00, 0x00, 0xff),
-    'ansipurple':      (0xff, 0x00, 0xff),
-    'ansiteal':        (0x00, 0xff, 0xff),
+    'ansired':         (0xff, 0x00, 0x00),
+    'ansigreen':       (0x00, 0xff, 0x00),
+    'ansiyellow':      (0xff, 0xff, 0x00),
+    'ansiblue':        (0x00, 0x00, 0xff),
+    'ansifuchsia':     (0xff, 0x00, 0xff),
+    'ansiturquoise':   (0x00, 0xff, 0xff),
 }
 
 
diff --git a/prompt_toolkit/terminal/win32_output.py b/prompt_toolkit/terminal/win32_output.py
index a6c2a8c..cf057d3 100644
--- a/prompt_toolkit/terminal/win32_output.py
+++ b/prompt_toolkit/terminal/win32_output.py
@@ -407,28 +407,27 @@ class BACKROUND_COLOR:
 def _create_ansi_color_dict(color_cls):
     " Create a table that maps the 16 named ansi colors to their Windows code. "
     return {
-        'ansiblack':   color_cls.BLACK,
-        'ansidefault': color_cls.BLACK,
-        'ansiwhite':   color_cls.GRAY | color_cls.INTENSITY,
-
+        'ansidefault':   color_cls.BLACK,
+        'ansiblack':     color_cls.BLACK,
+        'ansidarkgray':  color_cls.BLACK | color_cls.INTENSITY,
+        'ansilightgray': color_cls.GRAY,
+        'ansiwhite':     color_cls.GRAY | color_cls.INTENSITY,
+        
         # Low intensity.
-        'ansired':         color_cls.RED,
-        'ansigreen':       color_cls.GREEN,
-        'ansiyellow':      color_cls.YELLOW,
-        'ansiblue':        color_cls.BLUE,
-        'ansifuchsia':     color_cls.MAGENTA,
-        'ansiturquoise':   color_cls.CYAN,
-        'ansilightgray':   color_cls.GRAY,
-
+        'ansidarkred':     color_cls.RED,
+        'ansidarkgreen':   color_cls.GREEN,
+        'ansibrown':       color_cls.YELLOW,
+        'ansidarkblue':    color_cls.BLUE,
+        'ansipurple':      color_cls.MAGENTA,
+        'ansiteal':        color_cls.CYAN,
 
         # High intensity.
-        'ansidarkgray':    color_cls.BLACK | color_cls.INTENSITY,
-        'ansidarkred':     color_cls.RED | color_cls.INTENSITY,
-        'ansidarkgreen':   color_cls.GREEN | color_cls.INTENSITY,
-        'ansibrown':       color_cls.YELLOW | color_cls.INTENSITY,
-        'ansidarkblue':    color_cls.BLUE | color_cls.INTENSITY,
-        'ansipurple':      color_cls.MAGENTA | color_cls.INTENSITY,
-        'ansiteal':        color_cls.CYAN | color_cls.INTENSITY,
+        'ansired':        color_cls.RED | color_cls.INTENSITY,
+        'ansigreen':      color_cls.GREEN | color_cls.INTENSITY,
+        'ansiyellow':     color_cls.YELLOW | color_cls.INTENSITY,
+        'ansiblue':       color_cls.BLUE | color_cls.INTENSITY,
+        'ansifuchsia':    color_cls.MAGENTA | color_cls.INTENSITY,
+        'ansiturquoise':  color_cls.CYAN | color_cls.INTENSITY,
     }
 
 FG_ANSI_COLORS = _create_ansi_color_dict(FOREGROUND_COLOR)
diff --git a/tests/test_yank_nth_arg.py b/tests/test_yank_nth_arg.py
new file mode 100644
index 0000000..1ccec7b
--- /dev/null
+++ b/tests/test_yank_nth_arg.py
@@ -0,0 +1,85 @@
+from __future__ import unicode_literals
+from prompt_toolkit.buffer import Buffer
+from prompt_toolkit.history import InMemoryHistory
+
+import pytest
+
+
+ at pytest.fixture
+def _history():
+    " Prefilled history. "
+    history = InMemoryHistory()
+    history.append('alpha beta gamma delta')
+    history.append('one two three four')
+    return history
+
+
+# Test yank_last_arg.
+
+
+def test_empty_history():
+    buf = Buffer()
+    buf.yank_last_arg()
+    assert buf.document.current_line == ''
+
+
+def test_simple_search(_history):
+    buff = Buffer(history=_history)
+    buff.yank_last_arg()
+    assert buff.document.current_line == 'four'
+
+
+def test_simple_search_with_quotes(_history):
+    _history.append("""one two "three 'x' four"\n""")
+    buff = Buffer(history=_history)
+    buff.yank_last_arg()
+    assert buff.document.current_line == '''"three 'x' four"'''
+
+
+def test_simple_search_with_arg(_history):
+    buff = Buffer(history=_history)
+    buff.yank_last_arg(n=2)
+    assert buff.document.current_line == 'three'
+
+
+def test_simple_search_with_arg_out_of_bounds(_history):
+    buff = Buffer(history=_history)
+    buff.yank_last_arg(n=8)
+    assert buff.document.current_line == ''
+
+
+def test_repeated_search(_history):
+    buff = Buffer(history=_history)
+    buff.yank_last_arg()
+    buff.yank_last_arg()
+    assert buff.document.current_line == 'delta'
+
+
+def test_repeated_search_with_wraparound(_history):
+    buff = Buffer(history=_history)
+    buff.yank_last_arg()
+    buff.yank_last_arg()
+    buff.yank_last_arg()
+    assert buff.document.current_line == 'four'
+
+
+# Test yank_last_arg.
+
+
+def test_yank_nth_arg(_history):
+    buff = Buffer(history=_history)
+    buff.yank_nth_arg()
+    assert buff.document.current_line == 'two'
+
+
+def test_repeated_yank_nth_arg(_history):
+    buff = Buffer(history=_history)
+    buff.yank_nth_arg()
+    buff.yank_nth_arg()
+    assert buff.document.current_line == 'beta'
+
+
+def test_yank_nth_arg_with_arg(_history):
+    buff = Buffer(history=_history)
+    buff.yank_nth_arg(n=2)
+    assert buff.document.current_line == 'three'

-- 
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