prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

Completer after another completer. #1765

Open omicronns opened 12 months ago

omicronns commented 12 months ago

Hi, I wanted to use two completers one after another, but I'm not able to do that. FilesCompleter is my custom completer. After supplying the the file I want to trigger another completer BlockCompleter, but I don't know how to achieve that.

I tried following:

completer = NestedCompleter.from_nested_dict({
    'show': {
        'file': {
            FilesCompleter(): BlockCompleter()
        }
    },
})

But it gives me an error:

Exception 'FilesCompleter' object has no attribute 'lower'

Also another problem that I face is that for BlockCompleter to work I need result of FilesCompleter, but any of document methods or fields does not contain anything before the cursor position - eg. document.text is empty until i start typing.

What is the best way to achieve what I need?