
                         X    d dl mZ d dlmZmZ d dlZdZ G d de      Z G d de      Zy)	    )unicode_literals)	Completer
CompletionN)PathCompleterExecutableCompleterc                   "    e Zd ZdZ	 	 ddZd Zy)r   a  
    Complete for Path variables.

    :param get_paths: Callable which returns a list of directories to look into
                      when the user enters a relative path.
    :param file_filter: Callable which takes a filename and returns whether
                        this file should show up in the completion. ``None``
                        when no filtering has to be done.
    :param min_input_len: Don't do autocompletion when the input string is shorter.
    Nc                     |t        |      sJ |t        |      sJ t        |t              sJ t        |t              sJ || _        |xs d | _        |xs d | _        || _        || _        y )Nc                      dgS )N. r       ?lib/third_party/prompt_toolkit/contrib/completers/filesystem.py<lambda>z(PathCompleter.__init__.<locals>.<lambda>   s    ur   c                      y)NTr   )_s    r   r   z(PathCompleter.__init__.<locals>.<lambda>    s    Tr   )	callable
isinstanceintboolonly_directories	get_pathsfile_filtermin_input_len
expanduser)selfr   r   r   r   r   s         r   __init__zPathCompleter.__init__   sx     HY$777"h{&;;;----*d+++ 0"5}&:>*$r   c           	   #   ,  K   |j                   }t        |      | j                  k  ry 	 | j                  rt        j
                  j                  |      }t        j
                  j                  |      }|rY| j                         D cg c]?  }t        j
                  j                  t        j
                  j                  ||            A }}n| j                         }t        j
                  j                  |      }g }|D ]a  }	t        j
                  j                  |	      s#t	        j                  |	      D ]'  }
|
j                  |      s|j                  |	|
f       ) c t        |d       }|D ]  \  }	}
|
t        |      d  }t        j
                  j                  |	|
      }t        j
                  j                  |      r|
dz  }
n| j                  rf| j!                  |      sxt#        |d|
        y c c}w # t$        $ r Y y w xY ww)Nc                     | d   S )N   r   )ks    r   r   z/PathCompleter.get_completions.<locals>.<lambda>G   s    !r   )key/r   )display)text_before_cursorlenr   r   ospathdirnamer   joinbasenameisdirlistdir
startswithappendsortedr   r   r   OSError)r   documentcomplete_eventtextr(   pdirectoriesprefix	filenames	directoryfilename
completion	full_names                r   get_completionszPathCompleter.get_completions$   s    **
 t9t))).	ww))$/ ggood+G(,(8:(81  "wwrww||At/DE(8  : #nn. WW%%d+F I(	77==+$&JJy$9#..v6%,,i-BC %: ) yn=I (1#	8%c&kl3
GGLLH=	77==+ OH**''	2 QAA (1+:J  		sJ   &HAH AH AH $)H B1H ?H H 	HHHH)FNNr   F)__name__
__module____qualname____doc__r   r<   r   r   r   r   r      s    	 LP-2%7r   r   c                       e Zd ZdZd Zy)r   z<
    Complete only excutable files in the current path.
    c                 @    t         j                  | ddd d d      f y )NFr   c                  |    t         j                  j                  dd      j                  t         j                        S )NPATH )r&   environgetsplitpathsepr   r   r   r   z.ExecutableCompleter.__init__.<locals>.<lambda>g   s"    bjjnnVR8>>rzzJr   c                 J    t        j                  | t         j                        S )N)r&   accessX_OK)names    r   r   z.ExecutableCompleter.__init__.<locals>.<lambda>h   s    RYYtRWW%=r   T)r   r   r   r   r   )r   r   )r   s    r   r   zExecutableCompleter.__init__b   s,    "J= 	 	 	r   N)r=   r>   r?   r@   r   r   r   r   r   r   ^   s    r   r   )	
__future__r   prompt_toolkit.completionr   r   r&   __all__r   r   r   r   r   <module>rQ      s0    ' ; 	OI Od- r   