From fd61bfc73195063d984e7a1d3594015c7d5f4e25 Mon Sep 17 00:00:00 2001 From: Colton Baker Date: Fri, 17 Feb 2012 08:53:24 -0500 Subject: [PATCH] readline: ^Z (SIGSTP) handling 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. --- doc/api/readline.markdown | 4 ++++ lib/readline.js | 4 +++- lib/repl.js | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/api/readline.markdown b/doc/api/readline.markdown index 1fb90cf..9f9dbc2 100644 --- a/doc/api/readline.markdown +++ b/doc/api/readline.markdown @@ -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. @@ -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 diff --git a/lib/readline.js b/lib/readline.js index b93a4d5..2e16229 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -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 { @@ -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': @@ -568,6 +569,7 @@ Interface.prototype._ttyWrite = function(s, key) { case 'right': this._wordRight(); + break; } } else if (key.meta) { diff --git a/lib/repl.js b/lib/repl.js index 7abf0a3..b522d7a 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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); @@ -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(); -- 2.7.4