
    ^h                        S r SSKJr  SSKJrJrJrJrJr  SSK	J
r
JrJr  SSKJr  SSKJr  S/r\\\\\\   S\4   4   r " S	 S\5      rg)
zA
Nestedcompleter for completion of hierarchical data structures.
    )annotations)AnyIterableMappingSetUnion)CompleteEvent	Completer
Completion)WordCompleter)DocumentNestedCompleterNc                  f    \ rS rSrSr S	     S
S jjrSS jr\SS j5       r      SS jr	Sr
g)r      aw  
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                    Xl         X l        g )Noptionsignore_case)selfr   r   s      Z/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/completion/nested.py__init__NestedCompleter.__init__   s     &    c                @    SU R                   < SU R                  < S3$ )NzNestedCompleter(z, ignore_case=)r   )r   s    r   __repr__NestedCompleter.__repr__%   s$    !$,,!1@P@P?SSTUUr   c                ^   0 nUR                  5        H  u  p4[        U[        5      (       a  XBU'   M   [        U[        5      (       a  U R	                  U5      X#'   MJ  [        U[
        5      (       a(  U R	                  [        R                  U5      5      X#'   M  Ub   eSX#'   M     U " U5      $ )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)clsdatar   keyvalues        r   r"    NestedCompleter.from_nested_dict(   s    2 02**,JC%++$E4(("33E:E3''"33DMM%4HI}$}# ' 7|r   c              #  d  #    UR                   R                  5       n[        UR                   5      [        U5      -
  nSU;   a  UR                  5       S   nU R                  R                  U5      nUbg  U[        U5      S  R                  5       n[        U5      [        U5      -
  U-   n[        UUR                  U-
  S9n	UR                  X5       S h  vN   g g [        [        U R                  R                  5       5      U R                  S9nUR                  X5       S h  vN   g  NU N7f)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   r2   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D0D,AD0&D.'D0.D0)r   r   N)T)r   zdict[str, Completer | None]r   boolreturnNone)r@   str)r&   
NestedDictr@   r   )r5   r   r6   r	   r@   zIterable[Completion])__name__
__module____qualname____firstlineno____doc__r   r   classmethodr"   r2   __static_attributes__ r   r   r   r      sg    	 IM'2'AE'	'V $ $LK K2?K	Kr   )rH   
__future__r   typingr   r   r   r   r   prompt_toolkit.completionr	   r
   r   (prompt_toolkit.completion.word_completerr   prompt_toolkit.documentr   __all__rB   rC   r   rK   r   r   <module>rR      s\    # 5 5 J J B ,
 S%SXtY >??@
ZKi ZKr   