Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completer example #203

Open
blark opened this issue Dec 25, 2015 · 7 comments
Open

Completer example #203

blark opened this issue Dec 25, 2015 · 7 comments

Comments

@blark
Copy link

blark commented Dec 25, 2015

It would be really nice to have a basic and well documented completer example. I hacked something together from the other apps around based on prompt toolkit, it's here: https://gist.github.com/blark/46d6befc51909c7db4e0 But this only completes a list of words.

What I'm really interested in is context dependent recommendations... changing the recommendation based on the last word typed. I could probably figure out a way to do it, but the code would be ugly -- I'd love to see a clean example. THANKS!

@jonathanslenders
Copy link
Member

I'll put it on my to-do list. Thank for the request!

@blark
Copy link
Author

blark commented Jan 1, 2016

Thank you so much. I think I figured it out, I updated my gist (https://gist.github.com/blark/46d6befc51909c7db4e0) it now does context-dependent completions, but I'm probably doing it poorly. I would love to hear your feedback... Or if I'm not doing it poorly I can add it as an example and send a pull request :)

@ghost
Copy link

ghost commented Dec 19, 2016

@jonathanslenders I too am interested in such a feature. I'd also expand on @blark's request to recommend based on sequence of all words leading to the current word. This would allow building a complete command hierarchy and context.

For example, you could feed in a dictionary of commands:

colors = ["red", "green", "blue", "cyan", "magenta", "yellow"]
styles = ["normal", "bright"]

commands = {
    "set": {
        "color": {
            "fore": colors,
            "back": colors,
        },
        "style": styles
    },
    "get": {
        "color": ["fore", "back"],
        "style": None
    },
    "show": ["colors", "styles"]
}

prompt = prompt(">>", completer=NestedCompleter(commands))

I'd like to know if you are currently considering/working/fancy a PR on something like this?

@jonathanslenders
Copy link
Member

Hi @pshirali,

This functionality for the example you give is definitely useful. However, this is something that should be possible to build on top of prompt_toolkit, rather than inside of prompt_toolkit. It would be good for this to start as a separate project that implement the Completer interface. If it's proven to work well and useful for many people, then maybe we can merge it inside.

Actually, I also prefer to keep prompt_toolkit (the "core") to stay as small as possible, but have other people create tools around that.

Jonathan

@jonathanslenders
Copy link
Member

@blark: I noticed that it is a year ago that I replied, sorry about that. Is the question still relevant?

@blark
Copy link
Author

blark commented Dec 19, 2016

I learn best by example, I always like to see examples of best practice to understand how to start building something correctly. I have managed to figure out a solution, but would still love to see a very simple example of multi-level completions in the repo. But maybe that's just me...

@BlueRhino
Copy link

I implemented a NestedCompleter.It's here:https://gitee.com/BlueRhino/codes/q9yvef1whnmagdk3z0us259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants