Skip to content

Commit

Permalink
Fix inconsistent options.noHandleSIGINT for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
caub committed Mar 9, 2020
1 parent 8d5495c commit 756fa65
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/prompt.js
Expand Up @@ -86,22 +86,24 @@ prompt.start = function (options) {
prompt.delimiter = options.delimiter || prompt.delimiter;
prompt.colors = options.colors || prompt.colors;

if (process.platform !== 'win32' && !options.noHandleSIGINT) {
// windows falls apart trying to deal with SIGINT
process.on('SIGINT', function () {
stdout.write('\n');
process.exit(1);
});
} else {
// listen for the "Ctrl+C" key combination and trigger process event.
// See https://stackoverflow.com/questions/10021373/what-is-the-windows-equivalent-of-process-onsigint-in-node-js
stdin.on('keypress', function(char, key) {
if (key && key.ctrl && key.name == 'c') {
if (!options.noHandleSIGINT) {
if (process.platform !== 'win32') {
// windows falls apart trying to deal with SIGINT
process.on('SIGINT', function () {
stdout.write('\n');
process.emit("SIGINT");
process.exit(1);
}
});
});
} else {
// listen for the "Ctrl+C" key combination and trigger process event.
// See https://stackoverflow.com/questions/10021373/what-is-the-windows-equivalent-of-process-onsigint-in-node-js
stdin.on('keypress', function(char, key) {
if (key && key.ctrl && key.name == 'c') {
stdout.write('\n');
process.emit("SIGINT");
process.exit(1);
}
});
}
}

prompt.emit('start');
Expand Down

0 comments on commit 756fa65

Please sign in to comment.