o
    w¨Êh  ã                   @  sŽ   d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZmZ ddlmZ ddlmZ dgZeeeeee def f ZG d	d„ deƒZdS )
zA
Nestedcompleter for completion of hierarchical data structures.
é    )Úannotations)ÚAnyÚIterableÚMappingÚSetÚUnion)ÚCompleteEventÚ	CompleterÚ
Completion)ÚWordCompleter)ÚDocumentÚNestedCompleterNc                   @  s@   e Zd ZdZ	ddd	d
„Zddd„Zeddd„ƒZddd„ZdS )r   a“  
    Completer which wraps around several other completers, and calls any the
    one that corresponds with the first word of the input.

    By combining multiple `NestedCompleter` instances, we can achieve multiple
    hierarchical levels of autocompletion. This is useful when `WordCompleter`
    is not sufficient.

    If you need multiple levels, check out the `from_nested_dict` classmethod.
    TÚoptionsúdict[str, Completer | None]Úignore_caseÚboolÚreturnÚNonec                 C  s   || _ || _d S ©N©r   r   )Úselfr   r   © r   úR/var/www/html/env/lib/python3.10/site-packages/prompt_toolkit/completion/nested.pyÚ__init__   s   
zNestedCompleter.__init__Ústrc                 C  s   d| j ›d| j›d�S )NzNestedCompleter(z, ignore_case=ú)r   )r   r   r   r   Ú__repr__%   s   zNestedCompleter.__repr__ÚdataÚ
NestedDictc                 C  s„   i }|  ¡ D ]7\}}t|tƒr|||< qt|tƒr!|  |¡||< qt|tƒr3|  dd„ |D ƒ¡||< q|du s9J ‚d||< q| |ƒS )a²  
        Create a `NestedCompleter`, starting from a nested dictionary data
        structure, like this:

        .. code::

            data = {
                'show': {
                    'version': None,
                    'interfaces': None,
                    'clock': None,
                    'ip': {'interface': {'brief'}}
                },
                'exit': None
                'enable': None
            }

        The value should be `None` if there is no further completion at some
        point. If all values in the dictionary are None, it is also possible to
        use a set instead.

        Values in this data structure can be a completers as well.
        c                 S  s   i | ]}|d “qS r   r   )Ú.0Úitemr   r   r   Ú
<dictcomp>H   s    z4NestedCompleter.from_nested_dict.<locals>.<dictcomp>N)ÚitemsÚ
isinstancer	   ÚdictÚfrom_nested_dictÚset)Úclsr   r   ÚkeyÚvaluer   r   r   r%   (   s   




z NestedCompleter.from_nested_dictÚdocumentr   Úcomplete_eventr   úIterable[Completion]c           
      c  sÈ   � |j  ¡ }t|j ƒt|ƒ }d|v rM| ¡ d }| j |¡}|d urK|t|ƒd …  ¡ }t|ƒt|ƒ | }t||j| d�}	| |	|¡E d H  d S d S t	t
| j ¡ ƒ| jd�}| ||¡E d H  d S )Nú r   )Úcursor_position)r   )Útext_before_cursorÚlstripÚlenÚsplitr   Úgetr   r.   Úget_completionsr   ÚlistÚkeysr   )
r   r*   r+   ÚtextÚstripped_lenÚ
first_termÚ	completerÚremaining_textÚmove_cursorÚnew_documentr   r   r   r4   O   s&   €
þ÷ÿzNestedCompleter.get_completionsN)T)r   r   r   r   r   r   )r   r   )r   r   r   r   )r*   r   r+   r   r   r,   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úclassmethodr%   r4   r   r   r   r   r      s    ÿ
&)rA   Ú
__future__r   Útypingr   r   r   r   r   Úprompt_toolkit.completionr   r	   r
   Ú(prompt_toolkit.completion.word_completerr   Úprompt_toolkit.documentr   Ú__all__r   r   r   r   r   r   r   Ú<module>   s    