Created
February 28, 2014 13:29
-
-
Save PeterHancock/9271122 to your computer and use it in GitHub Desktop.
shotgun password
This file contains hidden or 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
//app.js | |
var readline = require('readline'), rl = null, .... | |
function startRl() { | |
rl = readline.createInterface(process.stdin, process.stdout); | |
rl.setPrompt('> '); | |
rl.on('line', function (userInput) { | |
shell.execute(userInput); | |
rl.prompt(); | |
}); | |
}; | |
// I found something similiar in a thread but I forget the source | |
function getPassword(callback) { | |
var stdin = process.stdin; | |
stdin.setRawMode(true); | |
stdin.setEncoding('utf8'); | |
var password = ''; | |
var onData = function onData(ch) { | |
ch = ch + ""; | |
switch (ch) { | |
case "\n": | |
case "\r": | |
case "\u0004": | |
//They've finished typing their password | |
process.stdout.write('\n'); | |
stdin.setRawMode(false); | |
stdin.removeListener('data', onData); | |
callback(false, password); | |
break; | |
case "\u0003": | |
// Ctrl-C | |
callback(true); | |
break; | |
default: | |
// More passsword characters | |
process.stdout.write('*'); | |
password += ch; | |
break; | |
} | |
}; | |
stdin.on('data', onData); | |
} | |
shell.on('password', function () { | |
//disable readline | |
rl.close(); | |
getPassword(function(cancel, password){ | |
startRl(); | |
shell.execute(password); | |
}); | |
}); | |
startRl(); | |
rl.prompt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think what you did here is perfectly fine. Because shotgun remains agnostic toward UI it doesn't make sense to include console password retrieval support within shotgun itself. However, as with shotgun-client (considering renaming to "shotgun-web-client") you could create a companion library that wraps shotgun and does provide all these helpful features :)