)L idZddlmZddlmZmZmZmZmZddl m Z m Z m Z ddl mZddlmZdgZeeeeeede ffZGd de Zy) zA Nestedcompleter for completion of hierarchical data structures. ) annotations)AnyIterableMappingSetUnion) CompleteEvent Completer Completion) WordCompleter)DocumentNestedCompleterNcTeZdZdZ d ddZd dZed dZ d dZy) ra 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)Noptions ignore_case)selfrrs f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/completion/nested.py__init__zNestedCompleter.__init__s &c<d|jd|jdS)NzNestedCompleter(z, ignore_case=)r)rs r__repr__zNestedCompleter.__repr__%s$!$,,!1@P@P?SSTUUrc>i}|jD]\}}t|tr|||<t|tr|j |||<At|t r(|j tj |||<y|Jd||<||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 dictfrom_nested_dictsetfromkeys)clsdatarkeyvalues rrz NestedCompleter.from_nested_dict(s202**, $JC%+$ E4("33E: E3'"33DMM%4HI }$}#  $7|rc#nK|jj}t|jt|z }d|vr|jd}|jj |}|k|t|dj}t|t|z |z}t ||j|z } |j| |Ed{yytt|jj|j}|j||Ed{y7Y7w)N r)cursor_position)r) text_before_cursorlstriplensplitrgetr r(get_completionsr listkeysr) rdocumentcomplete_eventtext stripped_len first_term completerremaining_text move_cursor new_documents rr.zNestedCompleter.get_completionsOs!**1138667#d)C  $;aJ ((4I$!%c*o&7!8!?!?!A!$i#n*== L '"$,$<$<{$J  %44\>RRR%&T\\&&()t7G7GI!00>J J JS Ks%CD5D1AD5+D3,D53D5N)T)rzdict[str, Completer | None]rboolreturnNone)r;str)r# NestedDictr;r)r1r r2r r;zIterable[Completion]) __name__ __module__ __qualname____doc__rr classmethodrr.rrrrsg IM'2'AE' ' V$$LK K2?K Kr)rB __future__rtypingrrrrrprompt_toolkit.completionr r r (prompt_toolkit.completion.word_completerr prompt_toolkit.documentr __all__r=r>rrDrrrKs\#55JJB,  S%SXtY >?? @ ZKiZKr