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    