Created
May 31, 2016 14:31
-
-
Save Darker/4bb715277e422dab2212a2540b83b004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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