dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Added ability to disable/ignore Ctrl+C #190

Open HarelAshwal opened 7 years ago

HarelAshwal commented 7 years ago

LK"I

Hi All,

Have you ever considered adding the ability to disable/ignore Ctrl+C ? I'm having application that the management console should always active. (and exiting options should be disabled)

Harel

MatthieuLemoine commented 7 years ago

If you want to disable CTRL+C you can remove all keypress listeners on process.stdin :

const listeners = process.stdin.removeAllListeners('keypress');

// You can restore them later 
listeners.forEach(listener => process.stdin.addListener('keypress', listener));

See Node documentation for more information.

LongLiveCHIEF commented 7 years ago

In addition to @MatthieuLemoine 's observations, it's also important to note that a vorpal app is actually a collection of vorpal instances. You can use the show and hide methods to get rid of the delimiter, while still keeping the app itself running, all without using the interrupt of Ctrl-C.

ORESoftware commented 6 years ago

there's also this handler, but I am not sure if it will help

process.prependListener('SIGINT', function(){

});

it might be nice if vorpal would ignore SIGINT events with a boolean, something like this:

process.once('SIGINT', function(){
    if(Vorpal.ignoreSIGINTEvents){
       return;
    }
});