sukeesh / Jarvis

Personal Assistant for Linux and macOS
MIT License
3.03k stars 1.04k forks source link

Improve Ctrl-C handling in interactive plugins #603

Open alexandr7035 opened 5 years ago

alexandr7035 commented 5 years ago

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: 1) 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) 2) 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....

pnhofmann commented 5 years ago

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.

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 ;).