pastel icon indicating copy to clipboard operation
pastel copied to clipboard

Is there an exit event / listener?

Open adam-lynch opened this issue 4 years ago • 2 comments

I ran into an issue where when using useInput or ink-select-input; pressing ctrl+c exits the app but not the process.

This is probably because our app has live connections. Is there a way I can subscribe to when the React app exits? I know there's waitUntilExit but I don't think that's accessible via Pastel (correct me if I'm wrong).

If exitOnCtrlC was set to false, I could check for key.ctrl && input === "c" in the useInput callback, and then call process.exit(0). I've confirmed this by editing the hook in node_modules. But:

  1. I want it to disable exitOnCtrlC at all.
  2. I don't think it can be disabled via Pastel (#35).
  3. I shouldn't have to manually handle ctrl+c anyway so this isn't a real solution 🤷‍♂️.

The workaround I'm using right now is to manually listen to stdin via useStdin. When ctrl+c is pressed (I've copied the logic from useInput), I call process.exit(0).

The awkward thing is that if any third-party component uses useInput, a workaround like this has to be used.

I think this is related to #8

adam-lynch avatar Aug 28 '20 11:08 adam-lynch

@adam-lynch You can simply import and edit the useInput method (these lines), and handle ctrl-c yourself (call exit() and process.exit(0))

JakeAdler avatar Sep 11 '20 23:09 JakeAdler

where are you suggesting I do this?

adam-lynch avatar Sep 22 '20 12:09 adam-lynch