summaryrefslogtreecommitdiff
path: root/keyboard.js
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2018-03-23 07:55:47 +0100
committertomsmeding <tom.smeding@gmail.com>2018-03-23 07:55:47 +0100
commit4ab4d924d9919ec4f5bfac81023e365b72fad8b7 (patch)
tree2dd0f3907876ec0a85f83aa52a4964e4a65f992e /keyboard.js
parent50af3d69af6d697e5e331fd4df0885b764575608 (diff)
Handjeswapper ~
Diffstat (limited to 'keyboard.js')
-rw-r--r--keyboard.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/keyboard.js b/keyboard.js
index e1101d8..1cd14dd 100644
--- a/keyboard.js
+++ b/keyboard.js
@@ -1,3 +1,5 @@
+const termios = require("node-termios");
+
module.exports = {};
let inputBuffer = "";
@@ -58,12 +60,41 @@ function getline() {
}
module.exports.getline = getline;
+function getpassword() {
+ return new Promise(async (resolve, reject) => {
+ const origtty = new termios.Termios(0);
+
+ const tty = new termios.Termios(0);
+ tty.c_lflag &= ~(termios.native.ALL_SYMBOLS.ECHO | termios.native.ALL_SYMBOLS.ECHONL);
+ tty.writeTo(0);
+
+ let handler;
+
+ try {
+ const line = await getline();
+ handler = () => resolve(line);
+ } catch (e) {
+ handler = () => reject(e);
+ }
+ console.log(); // ~ECHO eats newline
+ origtty.writeTo(0);
+ handler();
+ });
+}
+module.exports.getpassword = getpassword;
+
async function prompt(str) {
process.stdout.write(str);
return await getline();
}
module.exports.prompt = prompt;
+async function promptPassword(str) {
+ process.stdout.write(str);
+ return await getpassword();
+}
+module.exports.promptPassword = promptPassword;
+
function eof() {
return haveEOF;
}