o
    ˷e                     @   s   d Z ddlmZmZ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.
    )AnyDictIterableMappingOptionalSetUnion)CompleteEvent	Completer
Completion)WordCompleter)DocumentNestedCompleterNc                   @   st   e Zd ZdZ	ddeeee f deddfddZ	defd	d
Z
ededd fddZdededee f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ignore_casereturnNc                 C   s   || _ || _d S Nr   r   )selfr   r    r   W/var/www/ideatree/venv/lib/python3.10/site-packages/prompt_toolkit/completion/nested.py__init__   s   
zNestedCompleter.__init__c                 C   s   d| j d| jdS )NzNestedCompleter(z, ignore_case=)r   )r   r   r   r   __repr__#   s   zNestedCompleter.__repr__datac                 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>F   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documentcomplete_eventc           
      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/   M   s&   
zNestedCompleter.get_completions)T)__name__
__module____qualname____doc__r   strr   r
   boolr   r   classmethod
NestedDictr!   r   r	   r   r   r/   r   r   r   r   r      s(    
&)r<   typingr   r   r   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    $