Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update for 0.6 compatibility

  • Loading branch information...
commit ccddeba125eac9fc57ce21dd4d4d45151c98eaee 1 parent cdf804d
Isaac Z. Schlueter authored August 16, 2012
15  README.md
Source Rendered
@@ -33,6 +33,21 @@ Every option is optional.
33 33
 If silent is true, and the input is a TTY, then read will set raw
34 34
 mode, and read character by character.
35 35
 
  36
+## COMPATIBILITY
  37
+
  38
+This module works sort of with node 0.6.  It does not work with node
  39
+versions less than 0.6.  It is best on node 0.8.
  40
+
  41
+On node version 0.6, it will remove all listeners on the input
  42
+stream's `data` and `keypress` events, because the readline module did
  43
+not fully clean up after itself in that version of node, and did not
  44
+make it possible to clean up after it in a way that has no potential
  45
+for side effects.
  46
+
  47
+Additionally, some of the readline options (like `terminal`) will not
  48
+function in versions of node before 0.8, because they were not
  49
+implemented in the builtin readline module.
  50
+
36 51
 ## CONTRIBUTING
37 52
 
38 53
 Patches welcome.
15  lib/read.js
@@ -23,7 +23,13 @@ function read (opts, cb) {
23 23
   var def = opts.default || ''
24 24
   var terminal = !!(opts.terminal || output.isTTY)
25 25
   var rlOpts = { input: input, output: output, terminal: terminal }
26  
-  var rl = readline.createInterface(rlOpts)
  26
+
  27
+  if (process.version.match(/^v0\.6/)) {
  28
+    var rl = readline.createInterface(rlOpts.input, rlOpts.output)
  29
+  } else {
  30
+    var rl = readline.createInterface(rlOpts)
  31
+  }
  32
+
27 33
   var prompt = (opts.prompt || '').trim() + ' '
28 34
   var silent = opts.silent
29 35
   var editDef = false
@@ -69,6 +75,13 @@ function read (opts, cb) {
69 75
   function done () {
70 76
     called = true
71 77
     rl.close()
  78
+
  79
+    if (process.version.match(/^v0\.6/)) {
  80
+      rl.input.removeAllListeners('data')
  81
+      rl.input.removeAllListeners('keypress')
  82
+      rl.input.pause()
  83
+    }
  84
+
72 85
     clearTimeout(timer)
73 86
     output.mute()
74 87
     output.end()
7  test/basic.js
@@ -5,6 +5,11 @@ if (process.argv[2] === 'child') {
5 5
   return child()
6 6
 }
7 7
 
  8
+var CLOSE = 'close'
  9
+if (process.version.match(/^v0\.6/)) {
  10
+  CLOSE = 'exit'
  11
+}
  12
+
8 13
 var spawn = require('child_process').spawn
9 14
 
10 15
 tap.test('basic', function (t) {
@@ -31,7 +36,7 @@ tap.test('basic', function (t) {
31 36
     console.error('result %j', c.toString())
32 37
   })
33 38
 
34  
-  child.on('close', function () {
  39
+  child.on(CLOSE, function () {
35 40
     result = JSON.parse(result)
36 41
     t.same(result, {"user":"a user","pass":"a password","verify":"a password","passMatch":true})
37 42
     t.equal(output, 'Username: (test-user) Password: (<default hidden>) Password again: (<default hidden>) ')
7  test/defaults.js
@@ -5,6 +5,11 @@ if (process.argv[2] === 'child') {
5 5
   return child()
6 6
 }
7 7
 
  8
+var CLOSE = 'close'
  9
+if (process.version.match(/^v0\.6/)) {
  10
+  CLOSE = 'exit'
  11
+}
  12
+
8 13
 var spawn = require('child_process').spawn
9 14
 
10 15
 tap.test('defaults', function (t) {
@@ -31,7 +36,7 @@ tap.test('defaults', function (t) {
31 36
     console.error('result %j', c.toString())
32 37
   })
33 38
 
34  
-  child.on('close', function () {
  39
+  child.on(CLOSE, function () {
35 40
     result = JSON.parse(result)
36 41
     t.same(result, {"user":"test-user","pass":"test-pass","verify":"test-pass","passMatch":true})
37 42
     t.equal(output, 'Username: (test-user) Password: (<default hidden>) Password again: (<default hidden>) ')
7  test/many.js
... ...
@@ -1,6 +1,11 @@
1 1
 var tap = require('tap')
2 2
 var read = require('../lib/read.js')
3 3
 
  4
+var CLOSE = 'close'
  5
+if (process.version.match(/^v0\.6/)) {
  6
+  CLOSE = 'exit'
  7
+}
  8
+
4 9
 if (process.argv[2] === 'child') {
5 10
   return child()
6 11
 }
@@ -68,7 +73,7 @@ tap.test('many reads', function (t) {
68 73
     output += c
69 74
     console.error('' + c)
70 75
   })
71  
-  child.on('close', function (c) {
  76
+  child.on(CLOSE, function (c) {
72 77
     t.equal(output, expect)
73 78
     t.equal(n, 19)
74 79
     t.end()

0 notes on commit ccddeba

Please sign in to comment.
Something went wrong with that request. Please try again.