Skip to content

Instantly share code, notes, and snippets.

@Darker
Created May 31, 2016 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darker/4bb715277e422dab2212a2540b83b004 to your computer and use it in GitHub Desktop.
Save Darker/4bb715277e422dab2212a2540b83b004 to your computer and use it in GitHub Desktop.
const readline = require('readline');
var oldCreateIface = readline.createInterface;
readline.createInterface = function() {
var iface = oldCreateIface.apply(this, arguments);
var oldQuestion = iface.question;
iface.question = function(question) {
var promise = Promise.defer();
oldQuestion.call(this, question, (result)=>{
promise.resolve(result);
});
return promise.promise;
}
iface.choose = function(question) {
return rl.question(question+" [y/n]")
.then((a) => {
return a.toLowerCase()=="y";
})
}
return iface;
}
module.exports = readline;
const path = require("path");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var path1, path2;
rl.question("What is the first file?")
.then((name)=>{
path1 = name;
return rl.question("What is the second file?");
})
.then((name)=>{
path2 = name;
console.log("Relative path: ", path.relative(path1, path2));
process.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment