cursive
cursive copied to clipboard
Allow suppression of Event::Exit
Problem description
The termion backend puts stdout into raw mode which sets -ISIG to prevent the default SIGINT on Ctrl-C. In the event mapping from termion keys to cursive events, Ctrl-C is mapped directly to Event::Exit, and then in on_event on Cursive, Event::Exit is hardcoded directly to quit().
I'm working on a project where I do not want to quit on Ctrl-C (or any other automatic exit event), but it's not straightforward to me how to suppress exit on Ctrl-C with this setup.
Maybe instead of having the top level check for Event::Exit in on_event, this can be preloaded into a default global callback so that it can easily be cleared or overridden?
Sorry if I've missed something and this is already simple to do :^)
Environment
- Operating system: linux distribution, windows, macOS, ... GNU/Linux
- Backend used: ncurses (the default one), pancurses, termion, ... termion
- Current locale (run
localein a terminal). en_US.utf8 - Cursive version (from crates.io, from git, ...) 0.13.0 from crates.io
Hi, and thanks for the report!
That's a very good point, this ctrl-c forced handling does feel like it should be more flexible. A default global callback sounds like a great idea!
EDIT: Also, rather than hard-coding Ctrl-C to Exit in the backend and registering Exit -> Cursive::quit in the callback, we can just register Ctrl-C -> Cursive::quit in the callback, and drop the special handling in the backend entirely.
Some backends may still emit Exit (I think BearLibTerminal may do so when the window is closed).
On the latest master I use a regular OnEventView for the global callbacks. This lets us define pre and post-events, so we can now define the Ctrl-C callback as a pre-callback, which can be suppressed with Cursive::clear_global_callbacks (this will wipe both pre- and post- callbacks for this event).
I'm not sure that the clear global callbacks method is working as expected.
I am using siv.clear_global_callbacks(Event::CtrlChar('c'));
However it does not actually remove the existing pre_event added in reset_default_callbacks
Indeed! Seems like the Any dance around event identification didn't quite work quite as intended - should be all better on the latest master. Thanks for pointing that!