summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/qrcode-terminal/bin/qrcode-terminal.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/qrcode-terminal/bin/qrcode-terminal.js')
-rwxr-xr-xdeps/npm/node_modules/qrcode-terminal/bin/qrcode-terminal.js65
1 files changed, 49 insertions, 16 deletions
diff --git a/deps/npm/node_modules/qrcode-terminal/bin/qrcode-terminal.js b/deps/npm/node_modules/qrcode-terminal/bin/qrcode-terminal.js
index fcc7ee9d9a..64762879ef 100755
--- a/deps/npm/node_modules/qrcode-terminal/bin/qrcode-terminal.js
+++ b/deps/npm/node_modules/qrcode-terminal/bin/qrcode-terminal.js
@@ -9,35 +9,68 @@ var qrcode = require('../lib/main'),
fs = require('fs');
/*!
- * Parse the process name and input
+ * Parse the process name
*/
-var name = process.argv[1].replace(/^.*[\\\/]/, '').replace('.js', ''),
- input = process.argv[2];
+var name = process.argv[1].replace(/^.*[\\\/]/, '').replace('.js', '');
/*!
- * Display help
+ * Parse the input
*/
-if (!input || input === '-h' || input === '--help') {
- help();
- process.exit();
-}
+if (process.stdin.isTTY) {
+ // called with input as argument, e.g.:
+ // ./qrcode-terminal.js "INPUT"
-/*!
- * Display version
- */
+ var input = process.argv[2];
+ handleInput(input);
+} else {
+ // called with piped input, e.g.:
+ // echo "INPUT" | ./qrcode-terminal.js
-if (input === '-v' || input === '--version') {
- version();
- process.exit();
+ var readline = require('readline');
+
+ var interface = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ terminal: false
+ });
+
+ interface.on('line', function(line) {
+ handleInput(line);
+ });
}
/*!
- * Render the QR Code
+ * Process the input
*/
-qrcode.generate(input);
+function handleInput(input) {
+
+ /*!
+ * Display help
+ */
+
+ if (!input || input === '-h' || input === '--help') {
+ help();
+ process.exit();
+ }
+
+ /*!
+ * Display version
+ */
+
+ if (input === '-v' || input === '--version') {
+ version();
+ process.exit();
+ }
+
+ /*!
+ * Render the QR Code
+ */
+
+ qrcode.generate(input);
+}
/*!
* Helper functions