readline: ^Z (SIGSTP) handling
authorColton Baker <github@netrefuge.net>
Fri, 17 Feb 2012 13:53:24 +0000 (08:53 -0500)
committerisaacs <i@izs.me>
Thu, 23 Feb 2012 00:07:23 +0000 (16:07 -0800)
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
lib/readline.js
lib/repl.js

index 1fb90cf..9f9dbc2 100644 (file)
@@ -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
index b93a4d5..2e16229 100644 (file)
@@ -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) {
index 7abf0a3..b522d7a 100644 (file)
@@ -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();