prompt-toolkit / prompt-toolkit/python-prompt-toolkit

[Question] Set a custom delimiter in NestedCompletions

Open
#1,508 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

I am using python-prompt-toolkit for Autocompletion and its working perfectly fine for single completion .but i need to use Nested completion. consider the following example from docs:


from prompt_toolkit import prompt
from prompt_toolkit.completion import NestedCompleter


completer = NestedCompleter.from_nested_dict(
    {
        "show": 
            {"version": None,
           
           "clock": None, 
            
            "ip": {"interface": {"brief": None}}
            },
        "exit": None,
    }
)


def main():
    text = prompt("Type a command: ", completer=completer)
    print("You said: %s" % text)


if __name__ == "__main__":
    main()

while it does work,it only works when i use space as a delimiter(i.e,keep space between words) to separate the words,like
show version.however i want to use '\\' or '/'(depending on os) as delimiter,so it would be like show/ip/interface/brief(similar to how shell path completion works).i know you can do that,but i can't figure out how?.Thanks in advance

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the documented NestedCompleter.from_nested_dict example and inspect how prompt-toolkit separates nested completion words. Determine whether a configurable delimiter can support the requested slash or backslash path form; the work is done when the demonstrated nested command completes with that delimiter on the relevant operating system.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.