magmax/python-inquirer

How to add hooks for Checkbox

Closed this issue · 5 comments

I wanted to perform some functions when a checkbox in the inquirer list is toggled but when I tried doing that in a hacky way with the validation function, I don't see any arguments being passed to the validate function for checkbox type. Is there any way I can add some hooks for the checkbox type to do something as soon as some checkbox is toggled?

No there is no way to do that.

But why do you want it? I don't really see a usecase for it? Maybe there is a different approach not requiring this so maybe explain what you are trying to achive.

But if you have a valid usecase feel free to create a pull request

No there is no way to do that.

But why do you want it? I don't really see a usecase for it? Maybe there is a different approach not requiring this so maybe explain what you are trying to achive.

But if you have a valid usecase feel free to create a pull request

I am not sure if I'll be able to develop it but basically, it was just a convenience for me. I wanted that when I am selecting any checkbox, I can do some stuff with it. I am not sure if my example would be that relatable to you guys or not but basically, I want to keep the state (ON/OFF) associated with the List of items that I am passing to inquirer.

I won't say that I am using inquirer as maybe it is supposed to be used but check-box seemed apt for this use-case as I could turn on any of the items in the list and the checkbox would tell me the state of it in real time. Now the thing is that I am changing the state of the checkbox but I can't hook it at runtime to do the thing I want to do that is associated with the state change ( like actually toggling the hardware that is supposed to be with the state change ). That is why I was looking at the validation type of hook to do it. Am not sure if I was able to convey it well but something like this was my use case.

My use case doesn't want me to wait for the inquirer prompt as you see and just wants to stay in the inquirer session throughout the lifetime of the program to keep toggling the state as you see.

I know it can be achieved by me making a List and printing the status ( or appending it ) and keeping the inquirer in the while Loop but that doesn't seem too pretty to me given that checkbox actually does half the things that I want to be doing and I can potentially modify it like what I mentioned above.

Ok I understand what you are trying to do. Inquire is defnetly not the right libary for this. It was never meant to be a UI. Its designed to for forms, to ask a series of questions and process the answers in between.

So what your asking is defnetly out of scope sorry.


But feel free to fork the project and rewrite the validation callback handler to suite your needs.

You might also finde the underlying libary readchar interesting to build your own UI that accepts keypresses.

Or you might want to switch to a dedicated terminal-UI library

Thanks for letting me know @Cube707 . I'll see what I can do above it. Will be closing the issue as not planned