Skip to content

Commit

Permalink
Merge pull request #121 from rubbingalcoholic/master
Browse files Browse the repository at this point in the history
Add option to prompt.start to skip SIGINT handler
  • Loading branch information
gangstead committed Aug 5, 2016
2 parents e493cb8 + de836d8 commit e7b5449
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -425,6 +425,23 @@ get_username_prompt(_);
prompt.stop();
```

## Disabling prompt's built-in SIGINT handling

By default, prompt prompt binds a process-killing event handler to the SIGINT event (CTRL+C). This allows easily exiting from prompts, but can prevent an app from executing other event handlers when an interrupt is received. In order to override this default behavior, pass a `{noHandleSIGINT: true}` option into `prompt.start`.

``` js
//
// Disable prompt's built-in SIGINT handling:
//
prompt.start({noHandleSIGINT: true});

process.on('SIGINT', function() {
console.log("This will execute when you hit CTRL+C");
process.exit();
});
```


## Installation

``` bash
Expand Down
2 changes: 1 addition & 1 deletion lib/prompt.js
Expand Up @@ -86,7 +86,7 @@ prompt.start = function (options) {
prompt.delimiter = options.delimiter || prompt.delimiter;
prompt.colors = options.colors || prompt.colors;

if (process.platform !== 'win32') {
if (process.platform !== 'win32' && !options.noHandleSIGINT) {
// windows falls apart trying to deal with SIGINT
process.on('SIGINT', function () {
stdout.write('\n');
Expand Down

0 comments on commit e7b5449

Please sign in to comment.