o
    �õ±j  ã                   @  sŽ   d Z ddlmZ ddlmZmZ ddl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 B d	B e
B f ZG d
d„ de
ƒZd	S )zA
Nestedcompleter for completion of hierarchical data structures.
é    )Úannotations)ÚIterableÚMapping)ÚAny)Ú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   ú“/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/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 ]5\}}t|tƒr|||< qt|tƒr!|  |¡||< qt|tƒr1|  t |¡¡||< q|du s7J ‚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.
        N)ÚitemsÚ
isinstancer   ÚdictÚfrom_nested_dictÚsetÚfromkeys)Ú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   r/   P   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   r/   r   r   r   r   r      s    ÿ
&)r<   Ú
__future__r   Úcollections.abcr   r   Útypingr   Úprompt_toolkit.completionr   r   r   Ú(prompt_toolkit.completion.word_completerr	   Úprompt_toolkit.documentr
   Ú__all__r   r    r   r   r   r   r   r   Ú<module>   s    