Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent b3751b6 · Browse files · 2 files+6 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−5 removed

  • other:+6 added−5 removed

2 files+6 added−5 removed

modified:examples/input+3 added-3 removed
5 unmodified lines
67var program = require('../');89program.prompt('Username: ', function(name){10 console.log('hi %s', name);10 console.log('hi %s\n', name);1112 program.prompt('Description:', function(desc){13 console.log('description was "%s"', desc.trim());1415 program.prompt('Age: ', Number, function(age){16 console.log('age: %j', age);16 console.log('age: %j\n', age);1718 program.prompt('Birthdate: ', Date, function(date){19 console.log('date: %s', date);19 console.log('date: %s\n', date);20 process.stdin.destroy();21 });22 });23 });
1 unmodified line
modified:lib/commander.js+3 added-2 removed
668 unmodified lines
669 * @api private670 */671672Command.prototype.promptForDate = function(str, fn){673 var self = this;674 this.promptSingleLine(str, function(val){675 val = new Date(val);675 if (isNaN(val.getTime())) return program.promptForDate(str + '(must be a date) ', fn);676 if (isNaN(val.getTime())) return self.promptForDate(str + '(must be a date) ', fn);677 fn(val);678 });679};680
12 unmodified lines
693694 process.stdout.write(str);695 process.stdin.setEncoding('utf8');696 process.stdin.once('data', function(val){696 fn(val);697 fn(val.trim());698 }).resume();699};700701/**
223 unmodified lines