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.1k stars 717 forks source link

DefaultPrompt(Processor) equivalent in prompt_toolkit v2 #745

Open s4shyam95 opened 5 years ago

s4shyam95 commented 5 years ago

There used to be a DefaultPrompt(Processor) in v1, in layout/prompt.py Is there an equivalent or replacement for the same in v2 ?

jonathanslenders commented 5 years ago

Hi @s4shyam95,

For prompts, it is now recommended to use the PromptSession class, as explained in the documentation. This is an easy to use high level API that is guaranteed to remain stable.

If for some reason you want to implement this yourself, have a look at how PromptSession uses a get_line_prefix function to create the prompt.

s4shyam95 commented 5 years ago

I think there is a confusion, I am talking about the processor in v1 that used to enable stuff like the Ctrl+r (reverse history) search etc. That processor seems to have disappeared from v2.

Thanks, for your help.

jonathanslenders commented 5 years ago

Hi @s4shyam95, Reverse search has been completely refactored, because (among others) the way the focus implementation was changed. Before, it was a Buffer that was focused. Now, it's a UIControl that is focused. When the user starts searching and enters reverse search, it's a different UIControl and Buffer that gets focused. There is a prompt_toolkit.layout.processors.ReverseSearchProcessor that is applied around the search buffer, which displays the original text.

Again, unless you have a very custom layout, the PromptSession is absolutely what you should use for building any input prompts. This is well documented and has a stable API.

s4shyam95 commented 5 years ago

HI @jonathanslenders Thanks for your reply! We do have a costom layout, a bunch of nested splits (we had to make our own toolbar), due to which we are using a buffer and on accept_handler running the command in a coshell. We have also subclassed the Application class which we use to get extra information from _events of keybindings. Is there a way to use the ReverseSearch in this particular use case where the prompt is essentially a buffer, and everything is done manually ?