a
    õ£Ben  ã                   @  sp   d dl mZ d dlZd dlmZmZ d dlmZmZm	Z	 d dl
mZ ddgZG dd„ deƒZG d	d„ deƒZdS )
é    )ÚannotationsN)ÚCallableÚIterable)ÚCompleteEventÚ	CompleterÚ
Completion)ÚDocumentÚPathCompleterÚExecutableCompleterc                   @  s<   e Zd ZdZddddddd	d
œdd„Zddddœdd„ZdS )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.
    FNr   ÚboolzCallable[[], list[str]] | NonezCallable[[str], bool] | NoneÚintÚNone)Úonly_directoriesÚ	get_pathsÚfile_filterÚmin_input_lenÚ
expanduserÚreturnc                 C  s2   || _ |pdd„ | _|pdd„ | _|| _|| _d S )Nc                   S  s   dgS )NÚ.© r   r   r   úg/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/prompt_toolkit/completion/filesystem.pyÚ<lambda>$   ó    z(PathCompleter.__init__.<locals>.<lambda>c                 S  s   dS )NTr   )Ú_r   r   r   r   %   r   )r   r   r   r   r   )Úselfr   r   r   r   r   r   r   r   Ú__init__   s
    zPathCompleter.__init__r   r   zIterable[Completion])ÚdocumentÚcomplete_eventr   c                 #  sB  |j ‰ tˆ ƒ| jk rd S �z| jr.tj ˆ ¡‰ tj ˆ ¡}|rV‡ fdd„|  ¡ D ƒ}n|  ¡ }tj ˆ ¡}g }|D ]8}tj 	|¡rrt 
|¡D ]}| |¡rŒ| ||f¡ qŒqrt|dd„ d�}|D ]d\}}|t|ƒd … }	tj ||¡}
tj 	|
¡rü|d7 }n
| j�rqÀ|  |
¡�sqÀt|	d|d�V  qÀW n t�y<   Y n0 d S )	Nc                   s"   g | ]}t j t j |ˆ ¡¡‘qS r   )ÚosÚpathÚdirnameÚjoin)Ú.0Úp©Útextr   r   Ú
<listcomp><   s   z1PathCompleter.get_completions.<locals>.<listcomp>c                 S  s   | d S )Né   r   )Úkr   r   r   r   O   r   z/PathCompleter.get_completions.<locals>.<lambda>)Úkeyú/r   )r%   Zstart_positionÚdisplay)Ztext_before_cursorÚlenr   r   r   r   r    r   ÚbasenameÚisdirÚlistdirÚ
startswithÚappendÚsortedr!   r   r   r   ÚOSError)r   r   r   r    ÚdirectoriesÚprefixÚ	filenamesÚ	directoryÚfilenameÚ
completionZ	full_namer   r$   r   Úget_completions)   sH    
ÿ

ýzPathCompleter.get_completions)FNNr   F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r:   r   r   r   r   r	      s        úc                      s&   e Zd ZdZddœ‡ fdd„Z‡  ZS )r
   z=
    Complete only executable files in the current path.
    r   )r   c                   s$   t ƒ jdddd„ dd„ dd�f d S )NFr'   c                   S  s   t j dd¡ t j¡S )NÚPATHÚ )r   ÚenvironÚgetÚsplitÚpathsepr   r   r   r   r   s   r   z.ExecutableCompleter.__init__.<locals>.<lambda>c                 S  s   t  | t j¡S )N)r   ÚaccessÚX_OK)Únamer   r   r   r   t   r   T)r   r   r   r   r   )Úsuperr   )r   ©Ú	__class__r   r   r   o   s    ûzExecutableCompleter.__init__)r;   r<   r=   r>   r   Ú__classcell__r   r   rI   r   r
   j   s   )Ú
__future__r   r   Útypingr   r   Zprompt_toolkit.completionr   r   r   Zprompt_toolkit.documentr   Ú__all__r	   r
   r   r   r   r   Ú<module>   s   þ[