
    [                         d Z ddlmZ ddlmZmZ ddlmZ dZ G d de	      Z
 G d d	e	      Z G d
 d eee	            Zd Zd Zy)
    )unicode_literals)ABCMetaabstractmethod)with_metaclass)
Completion	CompleterCompleteEventget_common_complete_suffixc                   D    e Zd ZdZ	 	 d	dZd Zd Zd Zed        Z	d Z
y)
r   a  
    :param text: The new string that will be inserted into the document.
    :param start_position: Position relative to the cursor_position where the
        new text will start. The text will be inserted between the
        start_position and the original cursor position.
    :param display: (optional string) If the completion has to be displayed
        differently in the completion menu.
    :param display_meta: (Optional string) Meta information about the
        completion, e.g. the path or source where it's coming from.
    :param get_display_meta: Lazy `display_meta`. Retrieve meta information
        only when meta is displayed.
    Nc                     || _         || _        || _        || _        ||| _        n|| _        | j                  dk  sJ y )Nr   )textstart_position_display_meta_get_display_metadisplay)selfr   r   r   display_metaget_display_metas         ,lib/third_party/prompt_toolkit/completion.py__init__zCompletion.__init__   sH    	,)!1?DL"DL""a'''    c                    | j                   | j                  k(  r3| j                  j                  d| j                  d| j                  dS | j                  j                  d| j                  d| j                  d| j                   dS )Nz(text=z, start_position=)z
, display=)r   r   	__class____name__r   r   s    r   __repr__zCompletion.__repr__*   sg    <<499$''D4G4GI I ''D4G4G r   c                     | j                   |j                   k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S N)r   r   r   r   )r   others     r   __eq__zCompletion.__eq__3   s`    II# 45#7#774LLEMM)4 !3!33		5r   c                 p    t        | j                  | j                  | j                  | j                  f      S r    )hashr   r   r   r   r   s    r   __hash__zCompletion.__hash__:   s*    TYY 3 3T\\4CTCTUVVr   c                     | j                   | j                   S | j                  r!| j                         | _         | j                   S yN )r   r   r   s    r   r   zCompletion.display_meta=   sG     )%%%##!%!7!7!9D%%% r   c                     t        |t              r|| j                  z
  dk\  sJ t        | j                  || j                  z
  d | j
                  | j                  | j                        S )z
        (Only for internal use!)
        Get a new completion by splitting this one. Used by
        `CommandLineInterface` when it needs to have a list of new completions
        after inserting the common prefix.
        r   N)r   r   r   r   )
isinstanceintr   r   r   r   r   r   )r   positions     r   new_completion_from_positionz'Completion.new_completion_from_positionJ   sf     (C(X8K8K-Kq-PPP8d&9&99:;LL++!33	5 	5r   )r   NNN)r   
__module____qualname____doc__r   r   r"   r%   propertyr   r-    r   r   r   r      s?     KO"&(5W 
 
5r   r   c                       e Zd ZdZddZd Zy)r
   a6  
    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`.)
    c                 ,    |r|rJ || _         || _        y r    )text_insertedcompletion_requested)r   r5   r6   s      r   r   zCompleteEvent.__init__h   s"    !&:;; + %9!r   c                 h    | j                   j                  d| j                  d| j                  dS )Nz(text_inserted=z, completion_requested=r   )r   r   r5   r6   r   s    r   r   zCompleteEvent.__repr__q   s+    NN##T%7%79R9RT 	Tr   N)FF)r   r.   r/   r0   r   r   r2   r   r   r
   r
   Z   s    9Tr   r
   c                        e Zd ZdZed        Zy)r	   z3
    Base class for completer implementations.
    c              #      K   yw)z
        Yield :class:`.Completion` instances.

        :param document: :class:`~prompt_toolkit.document.Document` instance.
        :param complete_event: :class:`.CompleteEvent` instance.
        Nr2   )r   documentcomplete_events      r   get_completionszCompleter.get_completionsz   s      s   N)r   r.   r/   r0   r   r<   r2   r   r   r	   r	   v   s      r   r	   c                       fd}|D cg c]  } ||      s| }}t        |      t        |      k7  ryd }t        |D cg c]
  } ||       c}      S c c}w c c}w )z7
    Return the common prefix for all completions.
    c                 n    | j                   d | j                    }j                  j                  |      S r    )r   r   text_before_cursorendswith)
completionendr:   s     r   doesnt_change_before_cursorz?get_common_complete_suffix.<locals>.doesnt_change_before_cursor   s4    oo9
 9 99:**33C88r   r(   c                 6    | j                   | j                   d  S r    )r   r   )rA   s    r   
get_suffixz.get_common_complete_suffix.<locals>.get_suffix   s    
 9 99:;;r   )len_commonprefix)r:   completionsrC   ccompletions2rE   s   `     r   r   r      sm    
9  +M{!.I!.LA{LM <C,,< >A*Q->?? N ?s   AAAc                 |    | syt        |       }t        |       }t        |      D ]  \  }}|||   k7  s|d | c S  |S r'   )minmax	enumerate)stringss1s2irI   s        r   rG   rG      sK     \\bMDAqBqEz"1v " 	r   N)r0   
__future__r   abcr   r   sixr   __all__objectr   r
   r	   r   rG   r2   r   r   <module>rX      sU    ' ' H5 H5VTF T8w/  @.r   