Open craigh92 opened 4 years ago
I could create a fork / branch and assign myself to this if others think it is a useful feature?
I've gone ahead and made a fork, as this feature was easy to implement. A working example can be found here: https://github.com/craigh92/PyInquirer/blob/master/examples/callbacks.py
This looks good, I would go through it but I think we have something like this. @craigh92
@CITGuru Thanks for your reply.
If that is the case, could you please let me know how this is currently done?
Also, here's a better example of how it could be used:
https://github.com/craigh92/PyInquirer/blob/master/examples/calculator.py
I will be looking into this, this is fairly easy. I hope I could get enough time
I often want to perform an action as a result of a prompt choice/input:
For example:
As the number of options grows, and the prompts become more complex this can become messy, as you have to update the logic that handles the choice every time you change/add a choice.
It would be good if you could do something like:
This is better than the previous example because the callbacks are defined with the choices, so adding new behaviour to handle a new choice is easy.
The
handle
function can already be implemented now, without having to change any of the rest of the application. See below:But this relies on me being able to add the
callback
Dict item to thechoices
List. This currently happens to work, but as it is not an official feature I cannot guarantee that this will work with future versions of PyInquire. It would be good if thecallback
property could be officially supported.It would also be good if I could do the same with different types of prompts, such as
input
. For example:But unlike the
choices
example, this currently doesn't work and gives the error:Again, it would be good if the
callback
function could be called (with the input value) after the user has entered the input. Again, this could happen automatically, or by using some kind ofhandle
function.What do you think of this idea?