Skip to content

Commit

Permalink
readline: ^Z (SIGSTP) handling
Browse files Browse the repository at this point in the history
Bugfix and update.

- Fixed bug where Node's REPL wouldn't continue when returning from ^Z
  (SIGTSTP)
- Removed old readline callback

Readline API update with docs.

- ^Z (SIGTSTP) is now bypassed on Windows systems.
- SIGCONT is now bypassed on Windows systems.
- Docs updated to reflect above.
  • Loading branch information
Southern authored and isaacs committed Feb 23, 2012
1 parent ac9fa2b commit fd61bfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions doc/api/readline.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Example of listening for `SIGINT`:

`function () {}`

**This does not work on Windows.**

Emitted whenever the `in` stream receives a `^Z`, respectively known as
`SIGTSTP`. If there is no `SIGTSTP` event listener present when the `in` stream
receives a `SIGTSTP`, the program will be sent to the background.
Expand All @@ -164,6 +166,8 @@ Example of listening for `SIGTSTP`:

`function () {}`

**This does not work on Windows.**

Emitted whenever the `in` stream is sent to the background with `^Z`,
respectively known as `SIGTSTP`, and then continued with `fg`. This event only
emits if the stream was not paused before sending the program to the
Expand Down
4 changes: 3 additions & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ Interface.prototype._ttyWrite = function(s, key) {
break;

case 'z':
if (process.platform == 'win32') break;
if (this.listeners('SIGTSTP').length) {
this.emit('SIGTSTP');
} else {
Expand All @@ -547,7 +548,7 @@ Interface.prototype._ttyWrite = function(s, key) {
})(this));
process.kill(process.pid, 'SIGTSTP');
}
return;
break;

case 'w': // delete backwards to a word boundary
case 'backspace':
Expand All @@ -568,6 +569,7 @@ Interface.prototype._ttyWrite = function(s, key) {

case 'right':
this._wordRight();
break;
}

} else if (key.meta) {
Expand Down
6 changes: 3 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
self.displayPrompt();
});

rli.addListener('line', function(cmd) {
rli.on('line', function(cmd) {
sawSIGINT = false;
var skipCatchall = false;
cmd = trimWhitespace(cmd);
Expand Down Expand Up @@ -258,8 +258,8 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
};
});

rli.addListener('close', function() {
self.inputStream.destroy();
rli.on('SIGCONT', function() {
self.displayPrompt();
});

self.displayPrompt();
Expand Down

0 comments on commit fd61bfc

Please sign in to comment.