Comparing version 0.2.4 to 0.2.5
@@ -9,2 +9,3 @@ /* | ||
var events = require('events'), | ||
readline = require('readline'), | ||
utile = require('utile'), | ||
@@ -18,2 +19,17 @@ async = utile.async, | ||
// | ||
// Monkey-punch readline.Interface to work-around | ||
// https://github.com/joyent/node/issues/3860 | ||
// | ||
readline.Interface.prototype.setPrompt = function(prompt, length) { | ||
this._prompt = prompt; | ||
if (length) { | ||
this._promptLength = length; | ||
} else { | ||
var lines = prompt.split(/[\r\n]/); | ||
var lastLine = lines[lines.length - 1]; | ||
this._promptLength = lastLine.replace(/\u001b\[(\d+(;\d+)*)?m/g, '').length; | ||
} | ||
}; | ||
// | ||
// Expose version using `pkginfo` | ||
@@ -455,4 +471,4 @@ // | ||
default: defaultLine || null, | ||
stdin: stdin, | ||
stdout: stdout | ||
input: stdin, | ||
output: stdout | ||
}, function (err, line) { | ||
@@ -644,2 +660,2 @@ if (err) { | ||
return schema; | ||
} | ||
} |
{ | ||
"name": "prompt", | ||
"description": "A beautiful command-line prompt for node.js", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"author": "Nodejitsu Inc. <info@nodejitsu.com>", | ||
@@ -6,0 +6,0 @@ "maintainers": [ |
@@ -8,3 +8,3 @@ /* | ||
var events = require('events'), | ||
var stream = require('stream'), | ||
stream = require('stream'), | ||
@@ -20,5 +20,17 @@ util = require('util'), | ||
// | ||
var self = this; | ||
this.on('pipe', function (src) { | ||
var _emit = src.emit; | ||
src.emit = function () { | ||
//console.dir(arguments); | ||
_emit.apply(src, arguments); | ||
}; | ||
src.on('data', function (d) { | ||
self.emit('data', d + ''); | ||
}) | ||
}) | ||
}; | ||
util.inherits(MockReadWriteStream, events.EventEmitter); | ||
util.inherits(MockReadWriteStream, stream.Stream); | ||
@@ -101,3 +113,2 @@ ['resume', 'pause', 'setEncoding', 'flush'].forEach(function (method) { | ||
password: { | ||
default: 'Enter 12345 [backspace] [backspace]!', | ||
hidden: true, | ||
@@ -104,0 +115,0 @@ required: true |
@@ -12,2 +12,3 @@ /* | ||
helpers = require('./helpers'), | ||
macros = require('./macros'), | ||
schema = helpers.schema; | ||
@@ -27,16 +28,13 @@ | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
vows.describe('prompt').addBatch({ | ||
"When using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}, | ||
"the getInput() method": { | ||
@@ -59,2 +57,7 @@ "with a simple string prompt": { | ||
}, | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the getInput() method": { | ||
"with any field that is not supposed to be empty": { | ||
@@ -83,3 +86,8 @@ "and we don't provide any input": { | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the getInput() method": { | ||
"with a hidden field that is not supposed to be empty": { | ||
@@ -103,2 +111,9 @@ "and we provide valid input": { | ||
}, | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the getInput() method": { | ||
"with a hidden field that is not supposed to be empty": { | ||
"and we don't provide an input": { | ||
@@ -126,3 +141,8 @@ topic: function () { | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the getInput() method": { | ||
"with a complex property prompt": { | ||
@@ -144,3 +164,10 @@ "and a valid input": { | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the getInput() method": { | ||
"with a complex property prompt": { | ||
"and an invalid input": { | ||
@@ -175,3 +202,10 @@ topic: function () { | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the getInput() method": { | ||
"with a complex property prompt": { | ||
"with an invalid validator (array)": { | ||
@@ -199,14 +233,2 @@ topic: function () { | ||
"When using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}, | ||
"the get() method": { | ||
@@ -231,2 +253,9 @@ "with a simple string prompt": { | ||
}, | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the get() method": { | ||
"with a simple string prompt": { | ||
"that is a property name in prompt.properties": { | ||
@@ -253,2 +282,11 @@ "with a default value": { | ||
}, | ||
} | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the get() method": { | ||
"with a simple string prompt": { | ||
"that is a property name in prompt.properties": { | ||
"with a sync function validator (.validator)": { | ||
@@ -270,2 +308,11 @@ topic: function () { | ||
}, | ||
} | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the get() method": { | ||
"with a simple string prompt": { | ||
"that is a property name in prompt.properties": { | ||
"with a sync function validator (.conform)": { | ||
@@ -308,2 +355,7 @@ topic: function () { | ||
}, | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the get() method": { | ||
"skip prompt with prompt.overide": { | ||
@@ -322,14 +374,2 @@ topic: function () { | ||
"When using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}, | ||
"the addProperties() method": { | ||
@@ -350,14 +390,2 @@ topic: function () { | ||
"When using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}, | ||
"the get() method": { | ||
@@ -388,14 +416,2 @@ "with old schema": { | ||
"When using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}, | ||
"the history() method": { | ||
@@ -414,2 +430,9 @@ "when used inside of a complex property": { | ||
}, | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
"When using prompt": { | ||
"the history() method": { | ||
"when used inside of a complex property": { | ||
"with an incorrect value": { | ||
@@ -431,14 +454,2 @@ topic: function () { | ||
"when using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}, | ||
"the get() method": { | ||
@@ -456,15 +467,3 @@ topic: function () { | ||
}).addBatch({ | ||
"when using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}, | ||
"When using prompt": { | ||
"with fancy properties": { | ||
@@ -494,226 +493,127 @@ "the get() method": { | ||
} | ||
}).addBatch({ | ||
"when using prompt": { | ||
topic: function () { | ||
// | ||
// Reset the prompt for mock testing | ||
// | ||
prompt.started = false; | ||
prompt.start({ | ||
stdin: helpers.stdin, | ||
stdout: helpers.stdout | ||
}); | ||
return null; | ||
}).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'Y' | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'N' | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'YES' | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'NO' | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'T' | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'F' | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'TRUE' | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with a string message'], | ||
prop: 'test', | ||
response: 'FALSE' | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with an object', 'and description set'], | ||
prop: { description: 'a custom message' }, | ||
response: 'Y' | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with an object', 'and they forgot the description'], | ||
prop: { description: 'a custom message' }, | ||
response: 'Y' | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with an object', 'and custom validators'], | ||
prop: { | ||
description: 'node or jitsu?', | ||
pattern: /^(node|jitsu)/i, | ||
yes: /^node/i | ||
}, | ||
"the confirm() method": { | ||
"with a string message" : { | ||
"responding with Y" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('Y\n'); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"responding with N" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('N\n'); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
}, | ||
"responding with YES" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('YES\n'); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"responding with NO" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('NO\n'); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
}, | ||
"responding with T" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('T\n'); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"responding with F" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('F\n'); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
}, | ||
"responding with TRUE" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('TRUE\n'); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"responding with FALSE" : { | ||
topic: function () { | ||
prompt.confirm('test', this.callback); | ||
helpers.stdin.writeNextTick('FALSE\n'); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
} | ||
}, | ||
"with an object" : { | ||
"and description set" : { | ||
topic: function() { | ||
prompt.confirm({description:'a custom message'}, this.callback); | ||
helpers.stdin.writeNextTick('Y\n'); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"and they forgot the description" : { | ||
topic: function() { | ||
prompt.confirm({}, this.callback); | ||
helpers.stdin.writeNextTick('Y\n'); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"and custom validators" : { | ||
"responding node" : { | ||
topic: function() { | ||
prompt.confirm({ | ||
description: 'node or jitsu?', | ||
pattern: /^(node|jitsu)/i, | ||
yes: /^node/i | ||
}, this.callback); | ||
helpers.stdin.writeNextTick('node\n'); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"responding jitsu" : { | ||
topic: function() { | ||
prompt.confirm({ | ||
description: 'node or jitsu?', | ||
pattern: /^(node|jitsu)/i, | ||
yes: /^node/i | ||
}, this.callback); | ||
helpers.stdin.writeNextTick('jitsu\n'); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
} | ||
} | ||
} | ||
response: 'node' | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with an object', 'and custom validators'], | ||
prop: { | ||
description: 'node or jitsu?', | ||
pattern: /^(node|jitsu)/i, | ||
yes: /^node/i | ||
}, | ||
"with multiple strings" : { | ||
"responding with yesses" : { | ||
topic: function() { | ||
prompt.confirm(["test", "test2", "test3"], this.callback); | ||
helpers.stdin.writeSequence(['Y\n', 'y\n', 'YES\n']); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"responding with one no" : { | ||
topic: function() { | ||
prompt.confirm(["test", "test2", "test3"], this.callback); | ||
helpers.stdin.writeSequence(['Y\n', 'N\n', 'YES\n']); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
}, | ||
"responding with all noes" : { | ||
topic: function() { | ||
prompt.confirm(["test", "test2", "test3"], this.callback); | ||
helpers.stdin.writeSequence(['n\n', 'NO\n', 'N\n']); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
} | ||
}, | ||
"with multiple objects" : { | ||
"responding with yesses" : { | ||
topic: function() { | ||
prompt.confirm([ | ||
{ message: "test" }, | ||
{ message: "test2" } | ||
], this.callback); | ||
helpers.stdin.writeSequence(['y\n', 'y\n']); | ||
}, | ||
"should respond with true" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isTrue(result); | ||
} | ||
}, | ||
"responding with noes" : { | ||
topic: function() { | ||
prompt.confirm([ | ||
{ message: "test" }, | ||
{ message: "test2" } | ||
], this.callback); | ||
helpers.stdin.writeSequence(['n\n', 'n\n']); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
}, | ||
"responding with yes and no" : { | ||
topic: function() { | ||
prompt.confirm([ | ||
{ message: "test" }, | ||
{ message: "test2" } | ||
], this.callback); | ||
helpers.stdin.writeSequence(['n\n', 'y\n']); | ||
}, | ||
"should respond with false" : function(err, result) { | ||
assert.isNull(err); | ||
assert.isFalse(result); | ||
} | ||
} | ||
} | ||
} | ||
}).export(module); | ||
response: 'jitsu' | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with multiple strings'], | ||
prop: ["test", "test2", "test3"], | ||
response: ['Y\n', 'y\n', 'YES\n'] | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with multiple strings'], | ||
prop: ["test", "test2", "test3"], | ||
response: ['Y\n', 'N\n', 'YES\n'] | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with multiple strings'], | ||
prop: ["test", "test2", "test3"], | ||
response: ['n\n', 'NO\n', 'N\n'] | ||
}) | ||
).addBatch( | ||
macros.shouldConfirm({ | ||
messages: ['with multiple objects'], | ||
prop: [ | ||
{ message: "test" }, | ||
{ message: "test2" } | ||
], | ||
response: ['y\n', 'y\n'] | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with multiple objects'], | ||
prop: [ | ||
{ message: "test" }, | ||
{ message: "test2" } | ||
], | ||
response: ['n\n', 'n\n'] | ||
}) | ||
).addBatch( | ||
macros.shouldNotConfirm({ | ||
messages: ['with multiple objects'], | ||
prop: [ | ||
{ message: "test" }, | ||
{ message: "test2" } | ||
], | ||
response: ['n\n', 'y\n'] | ||
}) | ||
).export(module); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
24
0
111032
1933