
    f                        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e      Zy)
zA
Nestedcompleter for completion of hierarchical data structures.
    )annotations)AnyIterableMappingSetUnion)CompleteEvent	Completer
Completion)WordCompleter)DocumentNestedCompleterNc                  T    e Zd ZdZ	 d	 	 	 	 	 ddZd	dZed
d       Z	 	 	 	 	 	 ddZy)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.
    c                     || _         || _        y )Noptionsignore_case)selfr   r   s      [/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/completion/nested.py__init__zNestedCompleter.__init__   s     &    c                <    d| j                   d| j                  dS )NzNestedCompleter(z, ignore_case=)r   )r   s    r   __repr__zNestedCompleter.__repr__%   s$    !$,,!1@P@P?SSTUUr   c                @   i }|j                         D ]}  \  }}t        |t              r|||<   t        |t              r| j	                  |      ||<   At        |t
              r$| j	                  |D ci c]  }|d c}      ||<   u|J d||<     | |      S c c}w )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)clsdatar   keyvalueitems         r   r   z NestedCompleter.from_nested_dict(   s    2 02**, 		$JC%+$E4("33E:E3'"33E4RDT4Z4RS}$}#		$ 7| 5Ss   3
B
c              #  n  K   |j                   j                         }t        |j                         t        |      z
  }d|v r|j                         d   }| j                  j                  |      }|k|t        |      d  j                         }t        |      t        |      z
  |z   }t        ||j                  |z
        }	|j                  |	|      E d {    y y t        t        | j                  j                               | j                        }|j                  ||      E d {    y 7 Y7 w)N r   )cursor_position)r   )text_before_cursorlstriplensplitr   getr   r(   get_completionsr   listkeysr   )
r   documentcomplete_eventtextstripped_len
first_term	completerremaining_textmove_cursornew_documents
             r   r.   zNestedCompleter.get_completionsO   s!     **1138667#d)C $;aJ((4I $!%c*o&7!8!?!?!A!$i#n*==L'"$,$<$<{$J 
 %44\>RRR % &T\\&&()t7G7GI !00>JJJ S Ks%   CD5D1AD5+D3,D53D5N)T)r   zdict[str, Completer | None]r   boolreturnNone)r;   str)r"   
NestedDictr;   r   )r1   r   r2   r	   r;   zIterable[Completion])	__name__
__module____qualname____doc__r   r   classmethodr   r.    r   r   r   r      sg    	 IM'2'AE'	'V $ $LK K2?K	Kr   )rB   
__future__r   typingr   r   r   r   r   prompt_toolkit.completionr	   r
   r   (prompt_toolkit.completion.word_completerr   prompt_toolkit.documentr   __all__r=   r>   r   rD   r   r   <module>rK      s\    # 5 5 J J B ,
 S%SXtY >??@
ZKi ZKr   