Improve Ctrl-C handling in interactive plugins
If Ctrl-C shortcut is pressed in plugins which ask user for imput (like 'bmi'), jarvis is closed. Perhaps it would be better to return user back to the jarvis command line?
I'm trying to fix that using 2 diffrent SIGINT handlers and changing them in precmd() and postcmd() methods of Jarvis class. So, in precmd() the default nterrupt_handler() is disabled and then enabled again in postcmd(). But here is the problem I faced:
- In a new (second) ctrl-C hadnler I should stop the plugin. Is there a way to do that 'outside' the plugin itself? (from jarvis.py)
- How can I show '~> Hi, what can I do for you?' and ask for commands again?
I think I should open a PR to explain what i mean....
How can I show '~> Hi, what can I do for you?' and ask for commands again?
That's the easy question ;).
In a new (second) ctrl-C hadnler I should stop the plugin. Is there a way to do that 'outside' the plugin itself? (from jarvis.py)
This one is complicated...
Don't think there is something like a "clean" way to do so.
- Maybe by diverting Python debugging-features from its indended use?
- Or maybe start a thread for each command? A thread can probably be killed.
- Or simulate input of "exit" repetitively till command exits? But that would also imply, that all commands must exit when inputing exit. And won't stop commands, that are just "loading".
- Or put whole Jarvis in a loop. Something like:
ret = 42
while ret == 42:
ret = os.system('jarvis')
And then return in plugin_interrupt_handler 42, in cmd_interrupt_handler anything but 42.
Just my first thoughts ;).