Browse files

Fixed: line-buffered input automatically trimmed. Closes #31

  • Loading branch information...
1 parent b3751b6 commit 9745551846b7bcd64bf67298fe689b231f7ed911 @tj tj committed Nov 24, 2011
Showing with 6 additions and 5 deletions.
  1. +3 −3 examples/input
  2. +3 −2 lib/commander.js
View
6 examples/input
@@ -7,16 +7,16 @@
var program = require('../');
program.prompt('Username: ', function(name){
- console.log('hi %s', name);
+ console.log('hi %s\n', name);
program.prompt('Description:', function(desc){
console.log('description was "%s"', desc.trim());
program.prompt('Age: ', Number, function(age){
- console.log('age: %j', age);
+ console.log('age: %j\n', age);
program.prompt('Birthdate: ', Date, function(date){
- console.log('date: %s', date);
+ console.log('date: %s\n', date);
process.stdin.destroy();
});
});
View
5 lib/commander.js
@@ -670,9 +670,10 @@ Command.prototype.promptForNumber = function(str, fn){
*/
Command.prototype.promptForDate = function(str, fn){
+ var self = this;
this.promptSingleLine(str, function(val){
val = new Date(val);
- if (isNaN(val.getTime())) return program.promptForDate(str + '(must be a date) ', fn);
+ if (isNaN(val.getTime())) return self.promptForDate(str + '(must be a date) ', fn);
fn(val);
});
};
@@ -693,7 +694,7 @@ Command.prototype.promptSingleLine = function(str, fn){
process.stdout.write(str);
process.stdin.setEncoding('utf8');
process.stdin.once('data', function(val){
- fn(val);
+ fn(val.trim());
}).resume();
};

0 comments on commit 9745551

Please sign in to comment.