cursive icon indicating copy to clipboard operation
cursive copied to clipboard

Allow suppression of Event::Exit

Open toshokan opened this issue 5 years ago • 4 comments
trafficstars

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 locale in a terminal). en_US.utf8
  • Cursive version (from crates.io, from git, ...) 0.13.0 from crates.io

toshokan avatar Dec 30 '19 21:12 toshokan

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

gyscos avatar Dec 31 '19 07:12 gyscos

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

gyscos avatar Jan 26 '20 22:01 gyscos

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

jacob-pro avatar May 23 '20 23:05 jacob-pro

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!

gyscos avatar May 24 '20 01:05 gyscos