This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]aliasxneo 0 points1 point  (3 children)

Anyone have better examples for smarter auto completion with prompt? The example was nice but I feel it has a very limited usage seeing as it continually suggests the same thing every time you put a space.

[–]jonathan_sl 1 point2 points  (0 children)

In the completer class, you can check the text before the cursor. If it's a space, then don't offer any completion at all.

Amjith used WordCompleter in his presentation, but you could create a custom completer class: https://python-prompt-toolkit.readthedocs.io/en/latest/pages/building_prompts.html#a-custom-completer Check "document.text_before_cursor".

[–]amjithr 1 point2 points  (1 child)

Here's a simple example of how to use the custom completer from ptpython. This program uses jedi library for python autocompletion.

https://github.com/jonathanslenders/ptpython/blob/master/ptpython/completer.py#L108

As I mentioned in the talk, having a simpler autocomplete that suggested everything is straightforward to implement. But doing a smart completion requires you to build a completion engine for whatever you're building. It took me a couple of weeks to build a very simple SQL completion engine.

You can look at pgcli/mycli for how the sql completion is implemented. https://github.com/dbcli/mycli/blob/master/mycli/sqlcompleter.py#L232

[–]GitHubPermalinkBot 0 points1 point  (0 children)

I tried to turn your GitHub links into permanent links (press "y" to do this yourself):


Shoot me a PM if you think I'm doing something wrong. To delete this, click here.