Skip to content

Commit

Permalink
fix by @mm-gmbd - windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed Jul 23, 2015
1 parent c91f0bc commit 0cec7be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@ function prompt (message, hideInput, cb) {
if (key.ctrl && key.name === 'c') {
process.exit();
}
else if (key.name === 'return' || key.name === 'enter') {
else if (key.name === 'return'){
if (hideInput == true){
process.stdin.removeListener('keypress', listen);
process.stdin.pause();
setRawMode(false);
console.log();
cb(line, function () {}); // for backwards-compatibility, fake end() callback
}
return;
} else if (key.name === 'enter') {
process.stdin.removeListener('keypress', listen);
process.stdin.pause();
if (hideInput) {
setRawMode(false);
console.log();
}
cb(line, function () {}); // for backwards-compatibility, fake end() callback
cb(line.trim(), function () {}); // for backwards-compatibility, fake end() callback
return;
}
if (key.name === 'backspace') line = line.slice(0, -1);
Expand Down Expand Up @@ -97,7 +106,7 @@ function multi (questions, cb) {
}
else if (q.type === 'boolean') {
label += '(y/n) ';
q.validate = function (val) {
q.validate = function (val){
if (!val.match(/^(yes|ok|true|y|no|false|n)$/i)) return false;
};
}
Expand Down
13 changes: 13 additions & 0 deletions test/windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe('windows CRLF', function () {
it('works', function (done) {
suppose('node', [resolve(__dirname, '../examples/name.js')])
.on('enter your first name: ').respond('carlos\r\n')
.on('and your last name: ').respond('rodriguez\r\n')
.on('hi, carlos rodriguez!\n').respond("'sup!")
.error(assert.ifError)
.end(function (code) {
assert(!code);
done();
});
});
});

0 comments on commit 0cec7be

Please sign in to comment.